Exemplo n.º 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")
}
Exemplo n.º 2
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)))
}
Exemplo n.º 3
0
func (l *ConstHttpLocation) RoundTrip(r Request) (*http.Response, error) {
	req := r.GetHttpRequest()
	req.URL = netutils.MustParseUrl(l.Url)
	return http.DefaultTransport.RoundTrip(req)
}