diff options
author | Sergey Ponomarev <stokito@gmail.com> | 2021-11-08 14:09:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-08 13:09:35 +0100 |
commit | 8febad07979a5ee428f4b0747581c82af903737e (patch) | |
tree | e5dce029486d478e47fc29103b8b84539e8ad525 /http.go | |
parent | fix: Status Line parsing and writing (#1135) (diff) | |
download | fasthttp-8febad07979a5ee428f4b0747581c82af903737e.tar.gz fasthttp-8febad07979a5ee428f4b0747581c82af903737e.tar.bz2 fasthttp-8febad07979a5ee428f4b0747581c82af903737e.zip |
Currently, the only way to set URI for a request is to call SetRequestURI(string).
Then when a request performed the string will be parsed into a fasthttp.URI struct.
If there are many requests with the same URI then we'll waste CPU for a parsing of the same URI string.
With the new SetURI(*URI) method we can once parse a URI string into a fasthttp.URI struct and then reuse it for many requests.
Unfortunately the URI will be copied because may be modified inside the request.
But anyway this will be more lightweight than parsing.
Diffstat (limited to 'http.go')
-rw-r--r-- | http.go | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -774,6 +774,20 @@ func (req *Request) URI() *URI { return &req.uri } +// SetURI initializes request URI +// Use this method if a single URI may be reused across multiple requests. +// Otherwise, you can just use SetRequestURI() and it will be parsed as new URI. +// The URI is copied and can be safely modified later. +func (req *Request) SetURI(newUri *URI) { + if newUri != nil { + newUri.CopyTo(&req.uri) + req.parsedURI = true + return + } + req.uri.Reset() + req.parsedURI = false +} + func (req *Request) parseURI() error { if req.parsedURI { return nil |