summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-11 22:27:21 +0300
committerWolfy-J <[email protected]>2018-06-11 22:27:21 +0300
commit8880784ef5eea830820c2bb8eb5a9525f560beb3 (patch)
treee66ec8ee5a440b1c046fff38de0222869c289614 /service
parent1633a8ae539d423a88ec983b0bc531238d982a98 (diff)
cookies :)
Diffstat (limited to 'service')
-rw-r--r--service/http/server_test.go50
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)
+ }
+}