summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-05-02 16:33:45 +0300
committerWolfy-J <[email protected]>2019-05-02 16:33:45 +0300
commit64f2c19b0a9a33d97bd947e805d0491e68784423 (patch)
tree238b4a3f638b85180804458f97160455fcca1aff /service
parentcf3e341207893d62bae8a5671118401f745a8f08 (diff)
parent677004f7cb97981f0220e2c65a2e7618505d01dc (diff)
Merge branch 'feature/updates' into pr/issue-121-rename_maxrequest_config_param
Diffstat (limited to 'service')
-rw-r--r--service/http/handler_test.go52
-rw-r--r--service/http/parse.go4
-rw-r--r--service/http/parse_test.go2
3 files changed, 54 insertions, 4 deletions
diff --git a/service/http/handler_test.go b/service/http/handler_test.go
index 6df0a620..6cedd4cd 100644
--- a/service/http/handler_test.go
+++ b/service/http/handler_test.go
@@ -510,6 +510,58 @@ 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_Overwrite(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", "value1")
+ form.Add("key", "value2")
+
+ 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")
+
+ 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, `{"key":"value2","arr":{"x":{"y":null}}}`, string(b))
+}
+
func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
h := &Handler{
cfg: &Config{
diff --git a/service/http/parse.go b/service/http/parse.go
index 1f90930a..9b58d328 100644
--- a/service/http/parse.go
+++ b/service/http/parse.go
@@ -39,8 +39,8 @@ func (d dataTree) push(k string, v []string) {
// mount mounts data tree recursively.
func (d dataTree) mount(i []string, v []string) {
if len(i) == 1 {
- // single value context
- d[i[0]] = v[0]
+ // single value context (last element)
+ d[i[0]] = v[len(v)-1]
return
}
diff --git a/service/http/parse_test.go b/service/http/parse_test.go
index 34c0dc0d..f95a3f9d 100644
--- a/service/http/parse_test.go
+++ b/service/http/parse_test.go
@@ -50,5 +50,3 @@ func same(in, out []string) bool {
return true
}
-
-// bench