diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/http/server_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/service/http/server_test.go b/service/http/server_test.go index 33c6d44e..2499de7c 100644 --- a/service/http/server_test.go +++ b/service/http/server_test.go @@ -101,3 +101,53 @@ func TestServer_Headers(t *testing.T) { assert.Equal(t, "world", r.Header.Get("Header")) assert.Equal(t, "SAMPLE", string(b)) } + +func TestServer_Cookies(t *testing.T) { + st := &Server{ + cfg: &Config{ + MaxRequest: 1024, + Uploads: &UploadsConfig{ + Dir: os.TempDir(), + Forbid: []string{}, + }, + }, + rr: roadrunner.NewServer(&roadrunner.ServerConfig{ + Command: "php ../../php-src/tests/http/client.php cookie pipes", + Relay: "pipes", + Pool: &roadrunner.Config{ + NumWorkers: 1, + AllocateTimeout: 10000000, + DestroyTimeout: 10000000, + }, + }), + } + + assert.NoError(t, st.rr.Start()) + defer st.rr.Stop() + + hs := &http.Server{Addr: ":8077", Handler: st,} + defer hs.Shutdown(context.Background()) + + go func() { hs.ListenAndServe() }() + + req, err := http.NewRequest("GET", "http://localhost:8077", nil) + assert.NoError(t, err) + + req.AddCookie(&http.Cookie{Name: "input", Value: "input-value"}) + + 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, "INPUT-VALUE", string(b)) + + for _, c := range r.Cookies() { + assert.Equal(t, "output", c.Name) + assert.Equal(t, "cookie-output", c.Value) + } +} |