Commit Graph

365 Commits

Author SHA1 Message Date
Oleksandr Redko bbc7bd04e2 refactor: rename error local variables (#1738) 2024-03-25 14:30:27 +01:00
Oleksandr Redko 3166afd835 Enable few gocritic checks; fix up issues (#1728) 2024-03-02 16:19:05 +01:00
Co1a 5f81476d7c feat:support zstd compress and uncompressed (#1701)
* 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-21 07:21:52 +01:00
mopeneko b430b88e78 Implement GetRejectedConnectionsCount function (#1704)
* Implement `GetRejectedConnectionsCount`

* Implement test for `GetRejectedConnectionsCount`
2024-02-10 10:26:36 +01:00
Oleksandr Redko 28615eba55 Change empty string checks to be more idiomatic (#1684) 2024-01-04 15:05:38 +01:00
Oleksandr Redko 9d6b470260 chore: Add missing dots at the end of comments (#1677) 2023-12-13 13:56:24 +08:00
Oleksandr Redko 12949de784 chore: Set max line length to 130 characters (#1676) 2023-12-05 19:49:41 +01:00
Jille Timmermans 9b4e42affa bug: Flush the write buffer before putting it to the pool (#1672)
A few lines later we check if `s.ReduceMemoryUsage && hijackHandler == nil`
and call releaseWriter. We need to flush the buffer before returning it
to the pool to avoid the data getting lost.
2023-12-02 18:04:12 +01:00
Oleksandr Redko f196617f55 chore: Use 'any' instead of 'interface{}' (#1666)
gofmt -w -r "interface{} -> any" -l .
2023-11-24 11:33:04 +01:00
Oleksandr Redko d3397c64ed Enable wastedassign, whitespace linters; fix issues (#1665) 2023-11-24 11:32:11 +01:00
Alexander Kolesov c6a17b9a57 Don't put hijackConn structure back to the pool on Close if KeepHijackedConns is enabled. (#1629) 2023-10-06 21:34:33 +02:00
Oleksandr Redko 4ec5c5a774 docs: fix typos in comments and tests 2023-08-30 14:13:13 +02:00
Oleksandr Redko 9aa666e814 Enable gocritic linter; fix lint issues (#1612) 2023-08-29 20:08:37 +02:00
Zhang Xiaopei 6eb224954a fix:fasthttp server with tlsConfig (#1595)
* fix:fasthttp server with tlsConfig

Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com>

* fix:fasthttp server with tlsConfig

Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com>

* Update server.go

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>

* fix:fasthttp server with tlsConfig

Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com>

* fix:fasthttp server with tlsConfig

Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com>

---------

Signed-off-by: zhangweiyu <zhangweiyu2@huawei.com>
Co-authored-by: zhangweiyu <zhangweiyu2@huawei.com>
Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2023-07-18 13:00:15 +02:00
Oleksandr Redko d229959216 Remove unnecessary indent blocks (#1586) 2023-06-26 14:13:16 +02:00
Oleksandr Redko ffdf59d04c Enable gofumpt linter; format code gofumpt -w . (#1576) 2023-06-13 15:18:59 +02:00
Moritz Poldrack d0f2727a4d get rid of some panics (#1526)
* 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-30 03:38:28 +02:00
Oleksandr Redko 498a814fbf test: fix typos in function, error message, comment (#1512) 2023-03-06 16:55:21 +01:00
Oleksandr Redko 9230a3dd7a docs: Deprecate ErrAlreadyServing as never returning (#1491) 2023-02-13 10:44:47 +08:00
Oleksandr Redko e15a810a98 docs: fix grammar issues and typos in comments (#1492) 2023-02-13 10:43:44 +08:00
Oleksandr Redko 934f04e330 Refactor golangci-lint config and remove redundant nolints (#1486)
* 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-11 15:35:15 +08:00
Oleksandr Redko c0c5f9cd38 doc,test: correct typos (#1484) 2023-02-09 09:29:28 +01:00
Sergey Ponomarev 434022b461 server.go Simplify default Server name logic (#1467)
The serverName atomic.Value field is used as a cache. This is not needed and logic can be simplified.
See related #1458
2023-01-06 04:55:09 +01:00
kinggo c637221c5f optimize: allow http head when use getonly (#1456) 2022-12-25 09:38:13 +01:00
kinggo b788e663c6 feat: support custom formvalue function (#1453) 2022-12-25 09:37:49 +01:00
kinggo 2a572e08ef doc: optimize the comment of the Request.Done method (#1454) 2022-12-18 11:29:17 +01:00
kinggo 49951353c8 feat: add ShutdownWithContext (#1383) 2022-11-20 13:26:36 +02:00
kinggo 7b3bf58850 style: modify typo and remove repeated type conversions (#1437) 2022-11-18 08:13:18 +02:00
Andy Pan 8a60232af1 Assert with *net.TCPConn instead of *net.TCPListener in acceptConn() for TCP sockets (#1432)
Make the code more succinct.
2022-11-15 16:34:34 +01:00
pj d404f2db91 make RequestCtx's userdata accept keys that are of type: interface{} (#1387)
Co-authored-by: rocketlaunchr-cto <rocketlaunchr.cloud@gmail.com>
2022-10-06 16:25:32 +02:00
Erik Dubbelboer 28bec71c96 Fix "use of closed network connection" error check
This was refactored out incorrectly in a previous change.
2022-08-26 14:15:21 +02:00
Geralt X Li 3b147b7fe4 Fix(server): reset maxRequestBodySize to the server's config (#1360)
* fix(server): reset maxRequestBodySize to the server's config when HeaderReceived is set

* fix(server): reset writeTimeout
2022-08-23 16:44:59 +02:00
Aoang ea6052464e Add Go 1.19 Support (#1355)
* 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-08-14 11:31:57 +02:00
Erik Dubbelboer b23c5e9083 Close new connections after 5s in closeIdleConns
When calling closeIdleConns() also close new connections that haven't
received any data within 5 seconds.
Some applications open new connections but don't send anything and keep
them as keep-alive for potential future requests. We don't want to
keeping hanging on these when shutting down a server.
2022-06-28 11:04:21 +02:00
Y.Horie bc24f9d683 Consolidate TCPKeepalive in server.Serve (#1320) (#1324) 2022-06-20 21:42:05 +02:00
Sergey Ponomarev c9f43eaa1b Response.ContentEncoding(): store as field and avoid using 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-06-05 15:47:59 +02:00
Sergey Ponomarev de188244b4 Optimize server connection close logic (#1310)
* server.go Make code more clear

Inline isHTTP11 var.
Use direct Header.SetConnectionClose() and Header.ConnectionClose()

* server.go Use direct SetConnectionClose()

The SetCanonical(strConnection, strClose) call internally will anyway call SetConnectionClose().
The "Connection: close" will be printed in the ResponseHeader.AppendBytes()

* server.go Simplify connectionClose evaluation

The conn limit check merged into connectionClose evaluation.
This improves performance for most cases:
1. If the connectionClose already true then the conn limit check won't be performed.
2. The SetConnectionClose() was duplicated
3. First check conn limit and only then check for resp.connClose because most users don't close conns manually.
4. We may optimize more: If the resp.connClose = true then SetConnectionClose() not needed but as mentioned above this is a rare case.
2022-06-05 13:05:46 +02:00
Erik Dubbelboer 7cc6f4c513 Fix DoTimeout Streaming body bug 2022-04-26 00:45:51 +02:00
Erik Dubbelboer 7a5afddf5b Use %v for errors and %q for strings (#1262)
Mostly in tests.
2022-04-01 18:11:16 +02:00
Erik Dubbelboer b4152d1a99 Only set RequestCtx.s once
We have a RequestCtx pool per server so we only need to set it once.
This fixes a race codition where acquireCtx would assign .s while
.Done() is reading it. Even though acquireCtx would always set it to the
same, already assigned, value it would still trigger the race detector.

Fixes: https://github.com/valyala/fasthttp/issues/1261
2022-04-01 15:56:02 +02:00
Erik Dubbelboer d4c739eee5 State active (#1260)
* Require at least Go 1.15

* Fix StateActive state

* Don't panic when idle connections get closed
2022-04-01 10:18:48 +02:00
Aoang f3bce3aa6e Add Go 1.18 support (#1253)
* Add Go 1.18 support

* fix Gosec Security Scanner

https://github.com/valyala/fasthttp/runs/5595618634?check_suite_focus=true

* fix https://github.com/securego/gosec/issues/469#issuecomment-1070608395 Gosec Github Action Doesn't Work at Go 1.18

* fix https://github.com/golangci/golangci-lint/pull/2438 golangci/golangci-lint Doesn't Work at Go 1.18

* fix golint unused

* fix golint: SA1019: netErr.Temporary is deprecated

* fix https://github.com/valyala/fasthttp/issues/1256
2022-03-20 14:34:31 +01:00
Erik Dubbelboer 62c15a5d09 Don't reset RequestCtx.s (#1234)
RequestCtx's are reused in a server specific pool, so no need to reset
it. This fixes a use after reset but when RequestCtx is use as context.

Fixes #1205
2022-03-04 10:02:47 +01:00
Erik Dubbelboer 15262ecf3c Warn about unsafe ServeFile usage (#1228)
See: https://github.com/valyala/fasthttp/issues/1226
2022-03-03 08:51:13 +01:00
Pavel Burak 6937fee923 fix: (useless check), skip Response body if http method HEAD (#1224) 2022-02-20 18:14:24 +01:00
Sergio VS 436977654a fix(hijack): reuse RequestCtx (#1201)
* fix(hijack): reuse RequestCtx

* fix(test/hijack): increase wait time

* fix(test/hijack): wait for all connections to finish to check responses
2022-01-22 04:54:37 +01:00
Sergio VS 2aca3e8263 fix(hijack): reset userValues after hijack handler execution (#1199)
* fix(hijack): reset userValues after hijack handler execution

* feat: add test

* fix: typo

* fix(test): race condition
2022-01-18 12:45:41 +01:00
Kilos Liu 6b55811130 Add MaxIdleWorkerDuration to Server. (#1183) 2021-12-26 07:56:34 +01:00
Sergio VS 258a4c17b4 fix: reset response after reset user values on keep-alive connections (#1176) 2021-12-16 05:27:02 +01:00
Erik Dubbelboer e9db537178 Use %w to wrap errors (#1175) 2021-12-13 09:41:34 +01:00