Beispiel #1
0
func (s *LocSuite) TestChunkedEncodingLimitReached(c *C) {
	server := NewTestServer(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hi, I'm endpoint"))
	})
	defer server.Close()

	_, proxy := s.newProxyWithParams(s.newRoundRobin(server.URL), 0, 0, 4, 8)
	defer proxy.Close()

	conn, err := net.Dial("tcp", netutils.MustParseUrl(proxy.URL).Host)
	c.Assert(err, IsNil)
	fmt.Fprintf(conn, "POST / HTTP/1.0\r\nTransfer-Encoding: chunked\r\n\r\n4\r\ntest\r\n5\r\ntest1\r\n5\r\ntest2\r\n0\r\n\r\n")
	status, err := bufio.NewReader(conn).ReadString('\n')

	c.Assert(status, Equals, "HTTP/1.0 413 Request Entity Too Large\r\n")
}
Beispiel #2
0
func (s *CBSuite) TestRedirect(c *C) {
	cb := s.new(c,
		triggerNetRatio,
		fallbackRedirect,
		Options{
			FallbackDuration: 10 * time.Second,
			RecoveryDuration: 10 * time.Second,
		})

	req := makeRequest(O{})
	cb.metrics = statsNetErrors(0.6)
	re, err := cb.ProcessRequest(req)
	c.Assert(re, IsNil)
	c.Assert(err, IsNil)

	cb.ProcessResponse(req, req.Attempts[0])
	c.Assert(cb.state, Equals, cbState(stateTripped))

	re, err = cb.ProcessRequest(req)
	c.Assert(re, IsNil)
	c.Assert(err, DeepEquals, &errors.RedirectError{URL: netutils.MustParseUrl("http://localhost:5000")})
}
Beispiel #3
0
func (s *LocSuite) TestRewritesURLsWithEncodedPath(c *C) {
	var actualURL string

	server := NewTestServer(func(w http.ResponseWriter, r *http.Request) {
		actualURL = r.RequestURI
	})
	defer server.Close()

	_, proxy := s.newProxy(s.newRoundRobin(server.URL))
	defer proxy.Close()

	path := "/log/http%3A%2F%2Fwww.site.com%2Fsomething?a=b"
	url := netutils.MustParseUrl(proxy.URL)
	url.Opaque = path

	request, err := http.NewRequest("GET", url.String(), nil)
	request.URL = url

	http.DefaultClient.Do(request)

	c.Assert(err, IsNil)
	c.Assert(actualURL, Equals, path)
}
Beispiel #4
0
func (s *LocSuite) TestChunkedEncodingSuccess(c *C) {
	requestBody := ""
	contentLength := int64(0)
	server := NewTestServer(func(w http.ResponseWriter, r *http.Request) {
		body, err := ioutil.ReadAll(r.Body)
		c.Assert(err, IsNil)
		requestBody = string(body)
		contentLength = r.ContentLength
		w.Write([]byte("Hi, I'm endpoint"))
	})
	defer server.Close()

	_, proxy := s.newProxyWithParams(s.newRoundRobin(server.URL), 0, 0, 4, 4096)
	defer proxy.Close()

	conn, err := net.Dial("tcp", netutils.MustParseUrl(proxy.URL).Host)
	c.Assert(err, IsNil)
	fmt.Fprintf(conn, "POST / HTTP/1.0\r\nTransfer-Encoding: chunked\r\n\r\n4\r\ntest\r\n5\r\ntest1\r\n5\r\ntest2\r\n0\r\n\r\n")
	status, err := bufio.NewReader(conn).ReadString('\n')

	c.Assert(requestBody, Equals, "testtest1test2")
	c.Assert(status, Equals, "HTTP/1.0 200 OK\r\n")
	c.Assert(contentLength, Equals, int64(len(requestBody)))
}
func makeReq(url string) request.Request {
	u := netutils.MustParseUrl(url)
	return &request.BaseRequest{
		HttpRequest: &http.Request{URL: u},
	}
}
func (l *ConstHttpLocation) RoundTrip(r Request) (*http.Response, error) {
	req := r.GetHttpRequest()
	req.URL = netutils.MustParseUrl(l.Url)
	return http.DefaultTransport.RoundTrip(req)
}