Commit Graph

78 Commits

Author SHA1 Message Date
RW c4569c5fbb feat: enhance performance (#2135)
* feat: enhance performance

* fix: improve request URI parsing condition

* feat: validate HTTP date parsing and optimize status code length calculation

* Address parsing and lint issues

* chore: update Go version to 1.24.x in CI configuration

* feat: enhance HTTP date parsing and request URI handling

* refactor: optimize month and day name parsing using bitwise operations

* refactor: replace cookie token comparison with case insensitive function and streamline request URI parsing

* refactor: streamline request body handling and simplify request URI assignment

* chore: update Go version to 1.25.x in CI configuration

* feat: add fuzz testing for HTTP date parsing to improve robustness

* refactor: avoid unused return values in HTTP date parsing benchmarks

* refactor: update HTTP date parsing to use http.TimeFormat for consistency
2026-04-01 16:19:26 +09:00
Erik Dubbelboer 87f0fe1394 Update securego/gosec from 2.23.0 to 2.25.0 (#2161) 2026-03-20 07:27:24 +01:00
Erik Dubbelboer c2b317d47d Go 1.26 and golangci-lint updates (#2146)
Keep Go 1.24 compatibility for now (by not using `wg.Go()`).
2026-02-21 10:28:39 +01:00
Kashiwa e2bb2e0d64 Improve performance of ParseUfloat (#1865)
* Improve performance of ParseUfloat function

Replaced `offset` handling logic with more efficient math.Pow10 based calculation.

goos: linux
goarch: amd64
pkg: github.com/valyala/fasthttp
cpu: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
              │   old.txt   │           new.txt           │
              │   sec/op    │   sec/op     vs base        │
ParseUfloat-8   44.22n ± 0%   31.06n ± 0%  -29.76% (n=50)

* fix: lint error return value is not checked

* Handling uint64 overflow issues

* Implement ParseUfloat by calling strconv.ParseFloat

* fix: lint error
2024-09-22 15:46:29 +02:00
Juan Calderon-Perez bb0c8dd79c Replace custom AppendUint with strconv.AppendUint (#1813)
* Use strconv.AppendInt

* Replace AppendInt with AppendUint

* Fix typo
2024-07-31 21:59:52 +02:00
Oleksandr Redko e28be0c993 fix: panic in ParseIPv4 when len(dst) > 4 (#1742) 2024-03-29 14:11:50 +01:00
Oleksandr Redko 190204cf1a Upgrade golangci-lint to v1.56.2; fix gocritic issues (#1722) 2024-02-21 05:51:28 +01: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
Erik Dubbelboer 9d5a7bf7e3 Add support for Go 1.20 (#1481) 2023-02-03 08:41:39 +01:00
kinggo 7b3bf58850 style: modify typo and remove repeated type conversions (#1437) 2022-11-18 08:13:18 +02:00
tyltr 404c8a8968 Chore (#1365)
* chore-1

* chore2
2022-08-29 07:51:37 +02:00
ZhangYunHao 3101938850 Imporve AppendHTMLEscape fast path (#1249) 2022-03-17 14:52:47 +01:00
ZhangYunHao f7423e3def Fix AppendHTMLEscape (#1248) 2022-03-15 09:39:40 +01:00
Erik Dubbelboer e9db537178 Use %w to wrap errors (#1175) 2021-12-13 09:41:34 +01:00
tyltr 6006c8761d chore (#1137) 2021-10-30 15:58:20 +02:00
Oleg Kovalov adc0e57d0d Remove useless runtime.KeepAlive (#1107)
* Remove useless runtime.KeepAlive

* Update bytesconv.go
2021-09-20 16:33:03 +02:00
Erik Dubbelboer 46d92356a8 Check go fmt during lint (#1097) 2021-09-10 18:49:45 +02:00
YenForYang c7ce95f778 Fix s2b (#1079)
Ensure `len(b)` <= `cap(b)` at all times. Additionally, use `runtime.KeepAlive()` to prevent `s` from being GC-ed.
2021-08-26 10:09:45 +02:00
ZhangYunHao 52a8ab65e2 fix s2b go vet warning (#967) 2021-02-12 10:47:38 +01:00
Ivan Mironov 3e27d8ebad Fix integer overflow handling in parseUintBuf() (#789)
* Add more tests for parseUintBuf()

* Fix integer overflow handling in parseUintBuf()
2020-04-23 15:08:07 +02:00
RENAN.BASTOS 695f713fcf feat: workflow to verify security using GoSec (#747)
* feat: workflow to valid security using GoSec

* Update security.yml

* Fix gosec problems

These are all either false positives or os.Open operations done on
filenames supplied by the fasthttp user which we have to assume is safe.

* Just ignore some rules globally

* Fix more warnings

* No more warnings

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2020-02-28 21:03:48 +01:00
Erik Dubbelboer 32793db72d Run golangci-lint using a Github Action 2019-11-16 18:09:28 +01:00
ZhangYunHao b1ca43febc Use 'go generate' in bytesconv.go (#663)
* Add bytesconv_table_gen.go
2019-09-28 14:55:31 +02:00
ZYunH be93fbd21b Add lowerhex 2019-09-20 06:33:34 +03:00
ZYunH 79bd450e0e Use 0xf instead of 15 2019-09-20 06:33:34 +03:00
ZYunH 91138eed5f Replace int2hexbyte with uppercase 2019-09-20 06:33:34 +03:00
ZYunH 9bc19f85e1 Replace hexCharUpeer with upperhex (#657) 2019-09-19 13:15:51 +02:00
ZYunH ae421163c5 Improve appendQuotedPath and AppendQuotedArg (#654)
* Update bytesconv.go
* Modify tests
* Remove unnecessary comments
* Update args_test.go
* Add test for appendQuotedPath
* Fix 11202 issue
* Fix some problems
2019-09-18 13:52:04 +02:00
ZYunH c5413ffda8 A faster s2b function (#637)
* Use pointer for smaller stack space
2019-08-19 10:45:03 +02:00
Erik Dubbelboer 6453619524 Remove methods that had been deprecated in 2015 2019-02-16 15:10:39 +01:00
Erik Dubbelboer 8a9bdc8177 Fix ParseUint to support all possible numbers
Fixes #461
2018-11-14 01:59:18 +08:00
Iskander Sharipov 5c41b44ca7 use proper "Deprecated" comment format
Found using https://go-critic.github.io/overview#deprecatedComment-ref
2018-09-11 22:29:16 +03:00
Erik Dubbelboer 50bdd6c77c Fix appendQuotedPath to include all allowed characters 2018-09-05 20:06:18 +03:00
Jan Siemiński 6231e237de Add ';' to unescaped characters 2018-09-01 13:00:11 +08:00
Kirill Danshin 4a16377d6e Merge pull request #303 from chebyrash/master
Typo fixes
2018-08-13 23:18:55 +03:00
Aliaksandr Valialkin e5f51c1191 added missing byte 0xFF into hex2intTable. This fixes panic when decoding specially crafted string like "%\xff" 2017-12-07 14:09:41 +02:00
xPushkin f24d00fcc6 A lot of typo fixes 2017-10-08 13:30:35 +01:00
Aliaksandr Valialkin d257ae60a3 ioptimized decodeArgAppend a bit
Benchmark results on linux/amd64:

name                           old time/op  new time/op  delta
ArgsParse-4                    72.8ns ± 2%  68.0ns ± 2%  -6.59%  (p=0.000 n=10+9)
AppendUnquotedArgFastPath-4    20.4ns ± 2%  21.1ns ± 9%    ~     (p=0.614 n=8+10)
AppendUnquotedArgSlowPath-4    68.9ns ± 3%  70.4ns ± 6%    ~     (p=0.148 n=9+10)
URIParsePath-4                 80.9ns ± 2%  78.7ns ± 2%  -2.80%  (p=0.000 n=10+10)
URIParsePathQueryString-4      88.9ns ± 1%  86.3ns ± 1%  -2.90%  (p=0.000 n=10+8)
URIParsePathQueryStringHash-4  95.7ns ± 8%  91.0ns ± 1%  -4.88%  (p=0.000 n=9+10)
URIParseHostname-4             98.6ns ± 1%  95.4ns ± 1%  -3.24%  (p=0.000 n=10+10)
2017-07-21 16:08:21 +03:00
Aliaksandr Valialkin 52a0993b96 Issue #278: more optimizations for normalizeHeaderKey 2017-07-11 10:17:57 +03:00
Aliaksandr Valialkin 952171f61b Issue #278: optimize normalizeHeaderKey a bit
Performance results on amd64:

name                            old time/op  new time/op  delta
NormalizeHeaderKeyCommonCase-4  43.3ns ± 0%  32.6ns ± 1%  -24.80%  (p=0.000 n=9+10)
NormalizeHeaderKeyLowercase-4   42.6ns ± 3%  32.6ns ± 1%  -23.41%  (p=0.000 n=10+10)
NormalizeHeaderKeyUppercase-4   43.5ns ± 1%  32.6ns ± 2%  -25.03%  (p=0.000 n=9+8)

Based on top of https://github.com/valyala/fasthttp/pull/279 .
2017-07-10 14:28:06 +03:00
Aliaksandr Valialkin 0f5182f9ce added a fast path to AppendHTMLEscape when the string doesnt contain special chars 2017-06-23 19:04:29 +03:00
Aliaksandr Valialkin c0de95e84b Added AppendUnquotedArg - the complementary function to AppendQuotedArg 2017-06-19 18:35:07 +03:00
Aliaksandr Valialkin 033bb40f06 Properly handle hashes and single dots in URI.Update (see https://github.com/kataras/iris/issues/173) 2016-06-07 13:30:03 +03:00
Aliaksandr Valialkin 0f76772285 Do no allocate memory for error when an empty string is passed to ParseIPv4() 2016-04-28 13:07:09 +03:00
Aliaksandr Valialkin 9946a8145e bytesconv: reduce memory allocations on parse errors by using static errors 2016-03-30 20:49:09 +03:00
Aliaksandr Valialkin 0d43464f64 Renamed unsafeBytes2Str to b2s 2016-03-29 16:26:21 +03:00
Aliaksandr Valialkin 394c20fdc5 Added AppendHTMLEscape helper function 2016-02-15 16:53:44 +02:00
Aliaksandr Valialkin 52ddf98cfd Fixed golint warnings 2016-01-19 12:43:23 +02:00
Aliaksandr Valialkin 485098e5dc Exported AppendQuotedArg 2016-01-13 18:17:03 +02:00