Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Propagate Content-Type header if client sends it
Browse files Browse the repository at this point in the history
  • Loading branch information
georgy committed Jul 22, 2021
1 parent e6523b6 commit b97e406
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions selenoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ func create(w http.ResponseWriter, r *http.Request) {
r.URL.Host, r.URL.Path = u.Host, path.Join(u.Path, r.URL.Path)
newBody := removeSelenoidOptions(body)
req, _ := http.NewRequest(http.MethodPost, r.URL.String(), bytes.NewReader(newBody))
contentType := r.Header.Get("Content-Type")
if len(contentType) > 0 {
req.Header.Set("Content-Type", contentType)
}
ctx, done := context.WithTimeout(r.Context(), newSessionAttemptTimeout)
defer done()
log.Printf("[%d] [SESSION_ATTEMPTED] [%s] [%d]", requestId, u.String(), i)
Expand Down
24 changes: 24 additions & 0 deletions selenoid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,30 @@ func TestSessionCreatedWdHub(t *testing.T) {
queue.Release()
}

func TestSessionWithContentTypeCreatedWdHub(t *testing.T) {
root := http.NewServeMux()
root.Handle("/wd/hub/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/wd/hub")
AssertThat(t, r.Header.Get("Content-Type"), Is{"application/json; charset=utf-8"})
Selenium().ServeHTTP(w, r)
}))
manager = &HTTPTest{Handler: root}

resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "application/json; charset=utf-8", bytes.NewReader([]byte("{}")))
AssertThat(t, err, Is{nil})
var sess map[string]string
AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}})

resp, err = http.Get(With(srv.URL).Path("/status"))
AssertThat(t, err, Is{nil})
var state config.State
AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}})
AssertThat(t, state.Used, EqualTo{1})
AssertThat(t, queue.Used(), EqualTo{1})
sessions.Remove(sess["sessionId"])
queue.Release()
}

func TestSessionFailedAfterTimeout(t *testing.T) {
newSessionAttemptTimeout = 10 * time.Millisecond
manager = &HTTPTest{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit b97e406

Please sign in to comment.