summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-02-02 16:33:44 +0300
committerGitHub <[email protected]>2019-02-02 16:33:44 +0300
commit8a1cd5f4395852f57528c4d4a333efc96d674c17 (patch)
treed7434f9b17d5807fab11c0106357e9152fd64c0e
parentcd9e9a9118a201044774ac1ed4ccaf7913dd6ba4 (diff)
parent01148ad2c573b659d106edd7d8ad8065f7a2bea1 (diff)
Merge pull request #113 from Alex-Bond/bugfix/urlencoded-parsing
Fix application/x-www-form-urlencoded parsing
-rw-r--r--service/http/handler_test.go58
-rw-r--r--service/http/request.go2
2 files changed, 59 insertions, 1 deletions
diff --git a/service/http/handler_test.go b/service/http/handler_test.go
index 770158e5..aaf9760b 100644
--- a/service/http/handler_test.go
+++ b/service/http/handler_test.go
@@ -510,6 +510,64 @@ func TestHandler_FormData_POST(t *testing.T) {
assert.Equal(t, `{"arr":{"c":{"p":"l","z":""},"x":{"y":{"e":"f","z":"y"}}},"key":"value","name":["name1","name2","name3"]}`, string(b))
}
+func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
+ h := &Handler{
+ cfg: &Config{
+ MaxRequest: 1024,
+ Uploads: &UploadsConfig{
+ Dir: os.TempDir(),
+ Forbid: []string{},
+ },
+ },
+ rr: roadrunner.NewServer(&roadrunner.ServerConfig{
+ Command: "php ../../tests/http/client.php data pipes",
+ Relay: "pipes",
+ Pool: &roadrunner.Config{
+ NumWorkers: 1,
+ AllocateTimeout: 10000000,
+ DestroyTimeout: 10000000,
+ },
+ }),
+ }
+
+ assert.NoError(t, h.rr.Start())
+ defer h.rr.Stop()
+
+ hs := &http.Server{Addr: ":8083", Handler: h}
+ defer hs.Shutdown(context.Background())
+
+ go func() { hs.ListenAndServe() }()
+ time.Sleep(time.Millisecond * 10)
+
+ form := url.Values{}
+
+ form.Add("key", "value")
+ form.Add("name[]", "name1")
+ form.Add("name[]", "name2")
+ form.Add("name[]", "name3")
+ form.Add("arr[x][y][z]", "y")
+ form.Add("arr[x][y][e]", "f")
+ form.Add("arr[c]p", "l")
+ form.Add("arr[c]z", "")
+
+ req, err := http.NewRequest("POST", "http://localhost"+hs.Addr, strings.NewReader(form.Encode()))
+ assert.NoError(t, err)
+
+ req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
+
+ r, err := http.DefaultClient.Do(req)
+ assert.NoError(t, err)
+ defer r.Body.Close()
+
+ b, err := ioutil.ReadAll(r.Body)
+ assert.NoError(t, err)
+
+ assert.NoError(t, err)
+ assert.Equal(t, 200, r.StatusCode)
+
+ assert.Equal(t, `{"arr":{"c":{"p":"l","z":""},"x":{"y":{"e":"f","z":"y"}}},"key":"value","name":["name1","name2","name3"]}`, string(b))
+}
+
func TestHandler_FormData_PUT(t *testing.T) {
h := &Handler{
cfg: &Config{
diff --git a/service/http/request.go b/service/http/request.go
index 80e29f49..b1ca514a 100644
--- a/service/http/request.go
+++ b/service/http/request.go
@@ -153,7 +153,7 @@ func (r *Request) contentType() int {
}
ct := r.Headers.Get("content-type")
- if ct == "application/x-www-form-urlencoded" {
+ if strings.Contains(ct, "application/x-www-form-urlencoded") {
return contentFormData
}