Skip to content

Commit 70671d8

Browse files
committed
last element of POST data
1 parent c5f8f9d commit 70671d8

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

service/http/handler_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,58 @@ func TestHandler_FormData_POST(t *testing.T) {
510510
assert.Equal(t, `{"arr":{"c":{"p":"l","z":""},"x":{"y":{"e":"f","z":"y"}}},"key":"value","name":["name1","name2","name3"]}`, string(b))
511511
}
512512

513+
func TestHandler_FormData_POST_Overwrite(t *testing.T) {
514+
h := &Handler{
515+
cfg: &Config{
516+
MaxRequest: 1024,
517+
Uploads: &UploadsConfig{
518+
Dir: os.TempDir(),
519+
Forbid: []string{},
520+
},
521+
},
522+
rr: roadrunner.NewServer(&roadrunner.ServerConfig{
523+
Command: "php ../../tests/http/client.php data pipes",
524+
Relay: "pipes",
525+
Pool: &roadrunner.Config{
526+
NumWorkers: 1,
527+
AllocateTimeout: 10000000,
528+
DestroyTimeout: 10000000,
529+
},
530+
}),
531+
}
532+
533+
assert.NoError(t, h.rr.Start())
534+
defer h.rr.Stop()
535+
536+
hs := &http.Server{Addr: ":8083", Handler: h}
537+
defer hs.Shutdown(context.Background())
538+
539+
go func() { hs.ListenAndServe() }()
540+
time.Sleep(time.Millisecond * 10)
541+
542+
form := url.Values{}
543+
544+
form.Add("key", "value1")
545+
form.Add("key", "value2")
546+
547+
req, err := http.NewRequest("POST", "http://localhost"+hs.Addr, strings.NewReader(form.Encode()))
548+
assert.NoError(t, err)
549+
550+
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
551+
552+
r, err := http.DefaultClient.Do(req)
553+
assert.NoError(t, err)
554+
defer r.Body.Close()
555+
556+
b, err := ioutil.ReadAll(r.Body)
557+
assert.NoError(t, err)
558+
559+
assert.NoError(t, err)
560+
assert.Equal(t, 200, r.StatusCode)
561+
562+
assert.Equal(t, `{"key":"value2","arr":{"x":{"y":null}}}`, string(b))
563+
}
564+
513565
func TestHandler_FormData_POST_Form_UrlEncoded_Charset(t *testing.T) {
514566
h := &Handler{
515567
cfg: &Config{

service/http/parse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func (d dataTree) push(k string, v []string) {
3939
// mount mounts data tree recursively.
4040
func (d dataTree) mount(i []string, v []string) {
4141
if len(i) == 1 {
42-
// single value context
43-
d[i[0]] = v[0]
42+
// single value context (last element)
43+
d[i[0]] = v[len(v)-1]
4444
return
4545
}
4646

service/http/parse_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,3 @@ func same(in, out []string) bool {
5050

5151
return true
5252
}
53-
54-
// bench

0 commit comments

Comments
 (0)