mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-16 16:17:38 +03:00
Added CopyTo() to Request and Response
This commit is contained in:
@@ -105,6 +105,7 @@ func (h *RequestHeader) Clear() {
|
||||
|
||||
// CopyTo copies all the headers to dst.
|
||||
func (h *ResponseHeader) CopyTo(dst *ResponseHeader) {
|
||||
dst.Clear()
|
||||
dst.StatusCode = h.StatusCode
|
||||
dst.ContentLength = h.ContentLength
|
||||
dst.ConnectionClose = h.ConnectionClose
|
||||
@@ -115,6 +116,7 @@ func (h *ResponseHeader) CopyTo(dst *ResponseHeader) {
|
||||
|
||||
// CopyTo copies all the headers to dst.
|
||||
func (h *RequestHeader) CopyTo(dst *RequestHeader) {
|
||||
dst.Clear()
|
||||
dst.Method = append(dst.Method[:0], h.Method...)
|
||||
dst.RequestURI = append(dst.RequestURI[:0], h.RequestURI...)
|
||||
dst.ContentLength = h.ContentLength
|
||||
|
||||
@@ -11,7 +11,8 @@ import (
|
||||
|
||||
// Request represents HTTP request.
|
||||
//
|
||||
// It is forbidden copying Request instances. Create new instances instead.
|
||||
// It is forbidden copying Request instances. Create new instances
|
||||
// and use CopyTo() instead.
|
||||
type Request struct {
|
||||
// Request header
|
||||
Header RequestHeader
|
||||
@@ -35,7 +36,8 @@ type Request struct {
|
||||
|
||||
// Response represents HTTP response.
|
||||
//
|
||||
// It is forbidden copying Response instances. Create new instances instead.
|
||||
// It is forbidden copying Response instances. Create new instances
|
||||
// and use CopyTo() instead.
|
||||
type Response struct {
|
||||
// Response header
|
||||
Header ResponseHeader
|
||||
@@ -51,6 +53,27 @@ type Response struct {
|
||||
timeoutTimer *time.Timer
|
||||
}
|
||||
|
||||
// CopyTo copies req contents to dst.
|
||||
func (req *Request) CopyTo(dst *Request) {
|
||||
dst.Clear()
|
||||
req.Header.CopyTo(&dst.Header)
|
||||
dst.Body = append(dst.Body[:0], req.Body...)
|
||||
if req.parsedURI {
|
||||
dst.ParseURI()
|
||||
}
|
||||
if req.parsedPostArgs {
|
||||
dst.ParsePostArgs()
|
||||
}
|
||||
}
|
||||
|
||||
// CopyTo copies resp contents to dst.
|
||||
func (resp *Response) CopyTo(dst *Response) {
|
||||
dst.Clear()
|
||||
resp.Header.CopyTo(&resp.Header)
|
||||
dst.Body = append(dst.Body[:0], resp.Body...)
|
||||
dst.SkipBody = resp.SkipBody
|
||||
}
|
||||
|
||||
// ParseURI parses request uri and fills Request.URI.
|
||||
func (req *Request) ParseURI() {
|
||||
if req.parsedURI {
|
||||
|
||||
Reference in New Issue
Block a user