aboutsummaryrefslogtreecommitdiff
path: root/http.go
AgeCommit message (Collapse)AuthorFilesLines
2024-04-22fix: propagate body stream error to close function (#1743) (#1757)Gravatar Max Denushev 1-28/+48
* fix: propagate body stream error to close function (#1743) * fix: http test * fix: close body stream with error in encoding functions * fix: lint --------- Co-authored-by: Max Denushev <denushev@tochka.com>
2024-04-21refactor: do not return error as it is always nil (#1759)Gravatar Oleksandr Redko 1-26/+18
2024-03-25refactor: rename error local variables (#1738)Gravatar Oleksandr Redko 1-8/+8
2024-03-02Enable perfsprint linter; fix up lint issues (#1727)Gravatar Oleksandr Redko 1-2/+2
2024-03-02Enable few gocritic checks; fix up issues (#1728)Gravatar Oleksandr Redko 1-5/+5
2024-02-21feat:support zstd compress and uncompressed (#1701)Gravatar Co1a 1-0/+70
* feat:support zstd compress and uncompressed * fix:real & stackless write using different pool to avoid get stackless.writer * fix:zstd normalize compress level * Change empty string checks to be more idiomatic (#1684) * chore:lint fix and rebase with master * chore:remove 1.18 test & upgrade compress version * fix:error default compress level * Fix lint --------- Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2024-02-21Upgrade golangci-lint to v1.56.2; fix gocritic issues (#1722)Gravatar Oleksandr Redko 1-2/+2
2024-01-04Change empty string checks to be more idiomatic (#1684)Gravatar Oleksandr Redko 1-2/+2
2023-12-13chore: Add missing dots at the end of comments (#1677)Gravatar Oleksandr Redko 1-13/+19
2023-12-02writeBodyFixedSize: Only do an early flush if the reader is an *os.File (#1674)Gravatar Jille Timmermans 1-4/+13
or an *io.LimitedReader of an *os.File (because that's also supported by https://cs.opensource.google/go/go/+/refs/tags/go1.21.4:src/bufio/bufio.go;l=784) I think that having to flush less often outweighs the overhead of the extra check. The appended data is known to be large, but it might still save us a syscall by allowing it to buffer more.
2023-12-02copyZeroAlloc: Try WriteTo and ReadFrom before acquiring a buffer (#1673)Gravatar Jille Timmermans 1-0/+6
These are the same statements at the beginning of io.CopyBuffer, but by doing them ourselves first we trade off a little cpu for not holding the 4kb buffer during the write.
2023-11-24chore: Use 'any' instead of 'interface{}' (#1666)Gravatar Oleksandr Redko 1-1/+1
gofmt -w -r "interface{} -> any" -l .
2023-10-30Allow redirect URI path to not be normalized. (#1638)Gravatar Scott Kidder 1-0/+7
* Allow redirect URI path to not be normalized. * Introduce DisableRedirectPathNormalizing field to Request * Use field name as start of comment. Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> --------- Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-09-02Allow connection close for custom streams (#1603)Gravatar Armin Becher 1-1/+1
* feat: allow connection close for custom streams * fix: avoid req access since might already be released * fix: fix aloc test fails * fix: race condition when clossing body stream
2023-08-29Enable gocritic linter; fix lint issues (#1612)Gravatar Oleksandr Redko 1-12/+16
2023-08-16Update ErrNoMultipartFormGravatar Erik Dubbelboer 1-1/+1
Make it a more descriptive error message. Closes #1606
2023-07-08Fix round2Gravatar Erik Dubbelboer 1-23/+2
- don't limit it to 32 bits - give it a proper name - don't over-allocate too much
2023-07-02Auto add 'Vary' header after compression (#1585)Gravatar AutumnSun 1-0/+3
* Auto add 'Vary' header after compression Add config `SetAddVaryHeaderForCompression` to enable 'Vary: Accept-Encoding' header when compression is used. * feat: always set the Vary header * create and use `ResponseHeader.AddVaryBytes` * not export 'AddVaryBytes'
2023-06-13Enable gofumpt linter; format code `gofumpt -w .` (#1576)v1.48.0Gravatar Oleksandr Redko 1-2/+0
2023-04-12Fixed transfer-encoding for empty chunked payload (#1536)Gravatar Abe Saiovici 1-1/+4
2023-04-05support response body stream (#1414)Gravatar Anthony-Dong 1-4/+62
* feat: support response body stream * style: add header interface * Update http.go Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> * feat: support request、response、client stream * fix: close reader bug --------- Co-authored-by: fanhaodong.516 <fanhaodong.516@bytedance.com> Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-03-30get rid of some panics (#1526)Gravatar Moritz Poldrack 1-11/+15
* client: simplify (*HostClient).do() Remove an allocation in favour of deferring a call to release the response. * client: remove panic in dialAddr Return an error instead of panicking if the user supplied a nonsensical DialFunc. * compression: remove panic on invalid compression level If a compression level exceeding gzip's boundaries is provided, fasthttp will panic. Instead it would be better to handle this error for them by limiting it to the minimum or maximum value, depending on the direction the user has exceeded the limits. Clamp the value of gzip to always be between gzip.BestSpeed and gzip.BestCompression. * peripconn: remove panic on negative connection count When a negative count is reached when unregistering a connection, a panic is caused even though data-integrity is not at risk. Replace the panic() with a simple clamp on the value to ensure the value does not exceed it's expected lower bounds. References: #1504 * compress: remove error on failed nonblocking writes Since there is no way of handling or even logging non-critical errors in stateless non-blocking writecalls, just drop them and hope the user notices and tries again. * workerPool: remove panic on redundant Start and Stop calls Instead of panicking for invalid behaviour, it's preferable to just turn the function into a noop. * http: remove panic on invalid form boundary * http: remove panic on negative reads Since bufio already panics on negative reads, it is not necessary to do so as well. If the length is zero and for some reason no error is returned, readBodyIdentity and appendBodyFixedSize now errors in these cases. Link: https://github.com/golang/go/blob/851f6fd61425c810959c7ab51e6dc86f8a63c970/src/bufio/bufio.go#L246 * fs: remove panic on negative reader count When a negative count is reached when unregistering a reader, a panic is thrown even though data-integrity is not at risk. Replace the panic() with a simple clamp on the value to ensure the value does not exceed it's expected lower bounds. * server: remove panic in favour of a segfault Panicking with "BUG: " obscures the error. As the segfault causes a panic anyway, just let the chaos unfold. * server: remove panic in favour of returning an error Writing on a timed-out response is not endangering data integrity and just fails. * chore: add comments to all panics * chore: fix minor typo
2023-03-03http.go: close form file if copyZeroAlloc fails (#1498)Gravatar Oleksandr Redko 1-0/+1
2023-02-13docs: fix grammar issues and typos in comments (#1492)Gravatar Oleksandr Redko 1-1/+1
2023-02-11Refactor golangci-lint config and remove redundant nolints (#1486)Gravatar Oleksandr Redko 1-2/+2
* Refactor golangci-lint config - Use golangci-lint-action for GitHub workflow. - Add additional golangci-lint run options. - Remove unused nolint directives. * Revert exclude-use-default option
2023-02-10Rename unexported funcs, vars to match common Go (#1488)Gravatar Oleksandr Redko 1-3/+3
See https://github.com/golang/go/wiki/CodeReviewComments#initialisms and https://go.dev/doc/effective_go#mixed-caps
2023-01-23clear dst bodyRaw before copy (#1476)Gravatar tyltr 1-1/+1
2023-01-14fix: CopyTo doesn't copy bodyraw deeply (#1471)Gravatar kinggo 1-2/+2
2022-12-25optimize: allow http head when use getonly (#1456)Gravatar kinggo 1-2/+2
2022-11-16Fix some potential pool leaks (#1433)Gravatar Andy Pan 1-1/+2
2022-11-03Request.SetTimeout (#1415)Gravatar brian-armstrong-discord 1-0/+8
* Request.SetTimeout This functionally works the same as e.g. Client.DoTimeout(), but we can also use it for Client.DoRedirect(). There is no way as far as I can tell to set a timeout on a DoRedirect call, so this makes it possible. * tests * docs
2022-11-03fix form empty field error when used with pipe (#1417)Gravatar nick9822 1-1/+1
Co-authored-by: root <nikesh.tawde@digitalairtech.com>
2022-10-29fix: ignore body should not set content-length of streaming (#1406)Gravatar byene0923 1-1/+5
* fix: ignore body should not set content-length of streaming https://github.com/valyala/fasthttp/pull/1022 * fix: add commit
2022-08-14Add Go 1.19 Support (#1355)v1.39.0Gravatar Aoang 1-31/+31
* Update Go Version to Go1.19.x And add cache * Fix CI Line endings * Update test CI Go Version to Go1.19.x And add cache * Update Gosec Security Scanner CI to securego/gosec@v2.12.0 * Format comment Go 1.19 adds support for links, lists, and clearer headings in doc comments. As part of this change, gofmt now reformats doc comments to make their rendered meaning clearer. See “Go Doc Comments” for syntax details and descriptions of common mistakes now highlighted by gofmt. As another part of this change, the new package go/doc/comment provides parsing and reformatting of doc comments as well as support for rendering them to HTML, Markdown, and text. ref: https://tip.golang.org/doc/go1.19 ref: https://tip.golang.org/doc/comment * Fix doc structure
2022-07-29Prevent overflow and panic on large HTTP responses (#1351)Gravatar mathew 1-0/+6
2022-06-06BodyDecoded() for request and responses (#1308)Gravatar Sergey Ponomarev 1-0/+42
* header.go ContentEncoding() getter and setters For Response the CE header is stored into a separate field because compressed responses are often used. But for the Request let's just peek and store it from headers map * http.go: New BodyUncompressed() method for request and responses The new method returns a body and uncompress if it's gzipped
2022-06-05Response.ContentEncoding(): store as field and avoid using ↵Gravatar Sergey Ponomarev 1-6/+6
Header.SetCanonical() (#1311) * Response.ContentEncoding(): store as field The CE is not so often used for plain APIs responses and even not so often used for static files and on the fly compression. But still it should be checked each time. Also having a dedicated field getter and setter simplifies code * header.go Use shorter Response.setNonSpecial() and Request.setNonSpecial() methods instead of SetCanonical() The change should improve performance because the setSpecialHeader() call is omitted. As a downside on adding a new basic header field all putHeader() must be replaced with a direct getter and setter.
2022-04-26Fix DoTimeout Streaming body bugv1.36.0Gravatar Erik Dubbelboer 1-0/+11
2022-04-08add nil check of req.body and resp.body on ReleaseBody (#1266)Gravatar zzzzwc 1-1/+7
2022-04-01Use %v for errors and %q for strings (#1262)v1.35.0Gravatar Erik Dubbelboer 1-2/+2
Mostly in tests.
2022-03-14Read response when client closes connection #1232 (#1233)Gravatar ArminBTVS 1-0/+6
* Read response when client closes connection #1232 * Fix edge case were client responds with invalid header * Follow linter suggestions for tests * Changes after review * Reafactor error check after review * Handle connection reset on windows * Remove format string from test where not needed * Run connection reset tests not on Windows
2022-03-03feature: Keep the memory usage of the service at a stable level (#1216)Gravatar Rennbon 1-0/+18
* feature: add request and response body size limit, it prevents the large body from slowly stretching the memory of the entire service * fix: http.go fmt * refact: optimize code naming * Update http.go Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> * Update http.go Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> * Update http.go Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> * Update http.go Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> * Update http.go Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2021-12-28Release UseHostHeader in ReleaseRequest() (#1185)Gravatar Tolyar 1-0/+1
* Fix UseHostHeader for DoTimeout + tests * Release UseHostHeader in ReleaseRequest() + tests
2021-12-26Fix UseHostHeader for DoTimeout + tests (#1184)Gravatar Tolyar 1-0/+2
2021-12-17Allow to set Host header for Client (#1169)Gravatar Tolyar 1-3/+11
* Allow to set Host header for Client * Allow to change Host header without tests violation * Rename AllowToChangeHostHeader and add tests. * Allow to use empty uri.Host() when req.Header.Host() does not empty
2021-12-13Use %w to wrap errors (#1175)Gravatar Erik Dubbelboer 1-13/+13
2021-12-05Add trailer support (#1165)Gravatar ichx 1-33/+72
* Add trailer support * fix issue and add documentation * remove redundant code * add error return for add/set trailer method * fix lint error * fix bad trailer error return issue and update bad content-length error * update errNonNumericChars * update errNonNumericChars * fix issue about error and fix typo
2021-11-08http.go: Request.SetURI() (Fix #1141) (#1148)Gravatar Sergey Ponomarev 1-0/+14
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.
2021-10-22feat: ability to read body separate from header (#1130)Gravatar Shivansh Vij 1-9/+29
* Adding ConvertHTTPRequest and renaming ConvertRequest to ConvertFastRequest * Removing forServer boolean from ConvertHTTPRequest * Preparing for PR * Reverting adaptor changes * Fixing godoc, adding req.ReadBody function as well * Update comment to be more clear As per @erikdubbelboer suggestion Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com> Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2021-10-01Improve return value reusability documentationGravatar Erik Dubbelboer 1-2/+6