diff options
author | Wolfy-J <[email protected]> | 2019-07-29 16:05:30 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-07-29 16:05:30 +0300 |
commit | 196d89d47056a58345ee50dee1af799c4e3ec847 (patch) | |
tree | a4b096d42ad517c9d18761a4780dd6b9f8b59224 /service/http/h2c_test.go | |
parent | 2879c62c3cbdcde328ecc9bacee1d6d8fbdec44a (diff) |
- added support for H2C by @Alex-Bond
Diffstat (limited to 'service/http/h2c_test.go')
-rw-r--r-- | service/http/h2c_test.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/service/http/h2c_test.go b/service/http/h2c_test.go new file mode 100644 index 00000000..d806e5ff --- /dev/null +++ b/service/http/h2c_test.go @@ -0,0 +1,57 @@ +package http + +import ( + "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus/hooks/test" + "github.com/spiral/roadrunner/service" + "github.com/stretchr/testify/assert" + "net/http" + "testing" + "time" +) + +func Test_Service_H2C(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(ID, &Service{}) + + assert.NoError(t, c.Init(&testCfg{httpCfg: `{ + "address": ":6029", + "http2": {"h2c":true}, + "workers":{ + "command": "php ../../tests/http/client.php echo pipes", + "relay": "pipes", + "pool": { + "numWorkers": 1 + } + } + }`})) + + s, st := c.Get(ID) + assert.NotNil(t, s) + assert.Equal(t, service.StatusOK, st) + + // should do nothing + s.(*Service).Stop() + + go func() { c.Serve() }() + time.Sleep(time.Millisecond * 100) + defer c.Stop() + + req, err := http.NewRequest("PRI", "http://localhost:6029?hello=world", nil) + assert.NoError(t, err) + + req.Header.Add("Upgrade", "h2c") + req.Header.Add("Connection", "HTTP2-Settings") + req.Header.Add("HTTP2-Settings", "") + + r, err := http.DefaultClient.Do(req) + assert.NoError(t, err) + defer r.Body.Close() + + assert.Equal(t, "101 Switching Protocols", r.Status) + + // will fail with h2c notice +} |