func NewWebSocketApp(urls []route.Uri, rPort uint16, mbusClient yagnats.NATSConn, delay time.Duration) *TestApp { app := NewTestApp(urls, rPort, mbusClient, nil, "") app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) { defer ginkgo.GinkgoRecover() Expect(r.Header.Get("Upgrade")).To(Equal("websocket")) Expect(r.Header.Get("Connection")).To(Equal("upgrade")) conn, _, err := w.(http.Hijacker).Hijack() x := test_util.NewHttpConn(conn) resp := test_util.NewResponse(http.StatusSwitchingProtocols) resp.Header.Set("Upgrade", "websocket") resp.Header.Set("Connection", "upgrade") time.Sleep(delay) x.WriteResponse(resp) Expect(err).ToNot(HaveOccurred()) x.CheckLine("hello from client") x.WriteLine("hello from server") }) return app }
func shouldEcho(input string, expected string) { ln := registerHandler(r, "encoding", func(x *test_util.HttpConn) { x.CheckLine("GET " + expected + " HTTP/1.1") resp := test_util.NewResponse(http.StatusOK) x.WriteResponse(resp) x.Close() }) defer ln.Close() x := dialProxy(proxyServer) req := test_util.NewRequest("GET", "encoding", input, nil) x.WriteRequest(req) resp, _ := x.ReadResponse() Expect(resp.StatusCode).To(Equal(http.StatusOK)) }
"vulcan/router/proxy" "vulcan/router/test_util" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Session Affinity", func() { var done chan bool var jSessionIdCookie *http.Cookie responseNoCookies := func(x *test_util.HttpConn) { _, err := http.ReadRequest(x.Reader) Expect(err).ToNot(HaveOccurred()) resp := test_util.NewResponse(http.StatusOK) x.WriteResponse(resp) x.Close() done <- true } responseWithJSessionID := func(x *test_util.HttpConn) { _, err := http.ReadRequest(x.Reader) Expect(err).ToNot(HaveOccurred()) resp := test_util.NewResponse(http.StatusOK) resp.Header.Add("Set-Cookie", jSessionIdCookie.String()) x.WriteResponse(resp) x.Close() done <- true }
func (_ nullVarz) MarshalJSON() ([]byte, error) { return json.Marshal(nil) } func (_ nullVarz) ActiveApps() *stats.ActiveApps { return stats.NewActiveApps() } func (_ nullVarz) CaptureBadRequest(*http.Request) {} func (_ nullVarz) CaptureBadGateway(*http.Request) {} func (_ nullVarz) CaptureRoutingRequest(b *route.Endpoint, req *http.Request) {} func (_ nullVarz) CaptureRoutingResponse(b *route.Endpoint, res *http.Response, t time.Time, d time.Duration) { } var _ = Describe("Proxy", func() { It("responds to http/1.0 with path", func() { ln := registerHandler(r, "test/my_path", func(conn *test_util.HttpConn) { conn.CheckLine("GET /my_path HTTP/1.1") conn.WriteResponse(test_util.NewResponse(http.StatusOK)) }) defer ln.Close() conn := dialProxy(proxyServer) conn.WriteLines([]string{ "GET /my_path HTTP/1.0", "Host: test", }) conn.CheckLine("HTTP/1.0 200 OK") }) It("responds transparently to a trailing slash versus no trailing slash", func() { lnWithoutSlash := registerHandler(r, "test/my%20path/your_path", func(conn *test_util.HttpConn) {