func (s *RouterSuite) TestProxyPutRequest(c *C) { app := test.NewTestApp([]route.Uri{"greet.vcap.me"}, s.Config.Port, s.mbusClient, nil) var rr *http.Request var msg string app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) { rr = r b, err := ioutil.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return } msg = string(b) }) app.Listen() c.Assert(s.waitAppRegistered(app, time.Second*5), Equals, true) url := app.Endpoint() buf := bytes.NewBufferString("foobar") r, err := http.NewRequest("PUT", url, buf) c.Assert(err, IsNil) resp, err := http.DefaultClient.Do(r) c.Assert(err, IsNil) c.Assert(resp.StatusCode, Equals, http.StatusOK) c.Assert(rr, NotNil) c.Assert(rr.Method, Equals, "PUT") c.Assert(rr.Proto, Equals, "HTTP/1.1") c.Assert(msg, Equals, "foobar") }
func (s *RouterSuite) Test100ContinueRequest(c *C) { app := test.NewTestApp([]route.Uri{"foo.vcap.me"}, s.Config.Port, s.mbusClient, nil) rCh := make(chan *http.Request) app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) { _, err := ioutil.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) } rCh <- r }) <-s.WaitUntilNatsIsUp() app.Listen() go app.RegisterRepeatedly(1 * time.Second) c.Assert(s.waitAppRegistered(app, time.Second*5), Equals, true) host := fmt.Sprintf("foo.vcap.me:%d", s.Config.Port) conn, err := net.Dial("tcp", host) c.Assert(err, IsNil) defer conn.Close() fmt.Fprintf(conn, "POST / HTTP/1.1\r\n"+ "Host: %s\r\n"+ "Connection: close\r\n"+ "Content-Length: 1\r\n"+ "Expect: 100-continue\r\n"+ "\r\n", host) fmt.Fprintf(conn, "a") buf := bufio.NewReader(conn) line, err := buf.ReadString('\n') c.Assert(err, IsNil) c.Assert(strings.Contains(line, "100 Continue"), Equals, true) rr := <-rCh c.Assert(rr, NotNil) c.Assert(rr.Header.Get("Expect"), Equals, "") }
r.Run() }) AfterEach(func() { if natsRunner != nil { natsRunner.Stop() } if router != nil { router.Stop() } }) Context("Drain", func() { It("waits until the last request completes", func() { app := test.NewTestApp([]route.Uri{"drain.vcap.me"}, config.Port, mbusClient, nil) blocker := make(chan bool) resultCh := make(chan bool, 2) app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) { blocker <- true _, err := ioutil.ReadAll(r.Body) defer r.Body.Close() Ω(err).ShouldNot(HaveOccurred()) <-blocker w.WriteHeader(http.StatusNoContent) }) app.Listen()
config = createConfig(cfgFile, statusPort, proxyPort) }) JustBeforeEach(func() { gorouterSession = startGorouterSession(cfgFile) }) It("waits for all requests to finish", func() { mbusClient, err := newMessageBus(config) Expect(err).ToNot(HaveOccurred()) requestMade := make(chan bool) requestProcessing := make(chan bool) responseRead := make(chan bool) longApp := test.NewTestApp([]route.Uri{"longapp.vcap.me"}, proxyPort, mbusClient, nil, "") longApp.AddHandler("/", func(w http.ResponseWriter, r *http.Request) { requestMade <- true <-requestProcessing _, err := ioutil.ReadAll(r.Body) defer r.Body.Close() Expect(err).ToNot(HaveOccurred()) w.WriteHeader(http.StatusOK) w.Write([]byte{'b'}) }) longApp.Listen() routesUri := fmt.Sprintf("http://%s:%s@%s:%d/routes", config.Status.User, config.Status.Pass, localIP, statusPort) Eventually(func() bool { return appRegistered(routesUri, longApp) }).Should(BeTrue())
}).Should(BeTrue()) } sessionCookie, vcapCookie, port1 := getSessionAndAppPort("sticky.vcap.me", config.Port) port2 := getAppPortWithSticky("sticky.vcap.me", config.Port, sessionCookie, vcapCookie) Expect(port1).To(Equal(port2)) Expect(vcapCookie.Path).To(Equal("/")) for _, app := range apps { app.Unregister() } }) Context("Stop", func() { It("no longer proxies http", func() { app := test.NewTestApp([]route.Uri{"greet.vcap.me"}, config.Port, mbusClient, nil, "") app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) { _, err := ioutil.ReadAll(r.Body) defer r.Body.Close() Expect(err).ToNot(HaveOccurred()) w.WriteHeader(http.StatusNoContent) }) app.Listen() Eventually(func() bool { return appRegistered(registry, app) }).Should(BeTrue()) req, err := http.NewRequest("GET", app.Endpoint(), nil) Expect(err).ToNot(HaveOccurred())