Example #1
0
func NewRequest(c *fasthttp.RequestCtx) *Request {
	req := &Request{
		context: c,
		url:     &URL{url: c.URI()},
		header:  &RequestHeader{&c.Request.Header},
	}
	req.value = NewValue(req)
	req.response = NewResponse(c)
	return req
}
Example #2
0
func (s *Server) ServeHTTP(c *fasthttp.RequestCtx) {
	// Request
	req := s.pool.request.Get().(*Request)
	reqHdr := s.pool.requestHeader.Get().(*RequestHeader)
	reqURL := s.pool.url.Get().(*URL)
	reqHdr.reset(&c.Request.Header)
	reqURL.reset(c.URI())

	// Response
	res := s.pool.response.Get().(*Response)
	resHdr := s.pool.responseHeader.Get().(*ResponseHeader)
	resHdr.reset(&c.Response.Header)
	res.reset(c, resHdr)

	req.reset(res, c, reqHdr, reqURL)

	s.handler.ServeHTTP(req, res)

	s.pool.request.Put(req)
	s.pool.requestHeader.Put(reqHdr)
	s.pool.url.Put(reqURL)
	s.pool.response.Put(res)
	s.pool.responseHeader.Put(resHdr)
}