Commit Graph

84 Commits

Author SHA1 Message Date
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
Erik Dubbelboer a17ec74999 Reject bad ipv6 hostnames (#2076) 2025-10-05 03:14:32 +02:00
Erik Dubbelboer bed90bcf09 Reject invalid hosts with multiple port delimiters (#2077) 2025-10-05 02:46:46 +02:00
Erik Dubbelboer d3fc682391 Validate schemes (#2078) 2025-10-05 02:23:42 +02:00
Erik Dubbelboer af41f54adb Validate IPv6 addresses in urls (#2079) 2025-10-05 02:10:52 +02:00
Erik Dubbelboer 75dcdb8bba Fix username:password@ validation in urls (#2080) 2025-10-05 02:10:23 +02:00
Erik Dubbelboer 705ad0079a Fix parsing of bad urls with # (#1915)
http://google.com#@github.com parses incorrectly as github.com instead
of google.com.

Reported by Jesse Yang
2024-12-18 07:54:39 +01:00
Oleksandr Redko bc70d31d17 refactor: fix revive.indent-error-flow lint issues (#1896) 2024-11-10 20:09:27 +08:00
Kashiwa 9458f7a33c improve ishex and unhex by hex2intTable (#1883) 2024-10-18 22:51:22 +02:00
Juan Calderon-Perez 1fb3453165 Use Named Fields and Align Structures to Reduce Memory Usage (#1814)
* Use Named fields and Align Structures to Reduce Memory Usage

* Remove extra spaces
2024-08-02 22:26:52 +02:00
Oleksandr Redko 9d6b470260 chore: Add missing dots at the end of comments (#1677) 2023-12-13 13:56:24 +08: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 9aa666e814 Enable gocritic linter; fix lint issues (#1612) 2023-08-29 20:08:37 +02:00
Oleksandr Redko ffdf59d04c Enable gofumpt linter; format code gofumpt -w . (#1576) 2023-06-13 15:18:59 +02:00
Oleksandr Redko 5147cecec7 docs: replace links to golang.org with go.dev (#1489)
- Replace https://godoc.org with https://pkg.go.dev.
- Replace https://golang.org with https://go.dev.
- Replace https://golang.org/pkg with https://pkg.go.dev.
- Replace https://blog.golang.org with https://go.dev/blog.
- Use https://pkg.go.dev/golang.org/x/net/http2  instead of non-existing https://http2.golang.org/.
- Remove trailing slashes.
2023-02-11 19:59: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 f84e2346ba Rename unexported funcs, vars to match common Go (#1488)
See https://github.com/golang/go/wiki/CodeReviewComments#initialisms
and https://go.dev/doc/effective_go#mixed-caps
2023-02-10 21:34:49 +08:00
kinggo 776a4c721e fix: modify normalizePath (#1478) 2023-02-01 06:51:12 +01:00
tyltr 404c8a8968 Chore (#1365)
* chore-1

* chore2
2022-08-29 07:51:37 +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 7a5afddf5b Use %v for errors and %q for strings (#1262)
Mostly in tests.
2022-04-01 18:11:16 +02:00
Erik Dubbelboer 6b5bc7bb30 Add windows support to normalizePath
This is probably still not 100% sure and there are still many bugs with
FS on windows. But it's a slight improvement.

Fixes #1226
2022-02-28 11:56:59 +01:00
tyltr 61aa8b17a2 remove redundant code (#1202) 2022-01-27 03:17:00 +01:00
Sergey Ponomarev 3ff6aaa591 uri: isHttps() and isHttp() (#1150)
* uri: isHttps() and isHttp()

Use them instead of manual schema comparison

* uri: use SetSchemeBytes()
2021-11-08 13:35:26 +01:00
Erik Dubbelboer ad6d128614 URI.Parse should never change it's input
Decode the URI in place, but use the bytes of the URI instead of the
bytes of the input parameter.
2021-10-03 10:30:20 +02:00
Erik Dubbelboer ffab77a59d Improve return value reusability documentation 2021-10-01 13:38:31 +02:00
Erik Dubbelboer 542a203b42 Properly parse URI
Use URI parse code based on net/uri to validate hostnames.
2021-10-01 13:38:31 +02:00
Erik Dubbelboer 38992dafcf Fix []byte reuse bug
The return value of normalizePath should be a reusable []byte.
Returning strSlash could cause the strSlash constant to be reused and
resulted in very weird behavior. This specific case of normalizePath
almost never happens which made it even harder to spot.

The race detector on Windows was the only clue that something was
happening:

WARNING: DATA RACE
Write at 0x000001d082e3 by goroutine 446:
  github.com/valyala/fasthttp.addLeadingSlash()
      D:/a/fasthttp/fasthttp/uri_windows.go:8 +0xa5
  github.com/valyala/fasthttp.normalizePath()
      D:/a/fasthttp/fasthttp/uri.go:343 +0xbd
  github.com/valyala/fasthttp.(*URI).parse()
      D:/a/fasthttp/fasthttp/uri.go:314 +0x1606
  github.com/valyala/fasthttp.(*URI).Parse()
      D:/a/fasthttp/fasthttp/uri.go:266 +0xb3
  github.com/valyala/fasthttp.testURIPathNormalize()
      D:/a/fasthttp/fasthttp/uri_test.go:195 +0x47
  github.com/valyala/fasthttp.TestURIPathNormalize()
      D:/a/fasthttp/fasthttp/uri_test.go:176 +0x38e
  testing.tRunner()
      C:/hostedtoolcache/windows/go/1.15.15/x64/src/testing/testing.go:1123 +0x202

Previous read at 0x000001d082e3 by goroutine 332:
  runtime.slicecopy()
      C:/hostedtoolcache/windows/go/1.15.15/x64/src/runtime/slice.go:246 +0x0
  github.com/valyala/fasthttp.(*RequestHeader).AppendBytes()
      D:/a/fasthttp/fasthttp/header.go:1726 +0x24d
  github.com/valyala/fasthttp.(*RequestHeader).Header()
      D:/a/fasthttp/fasthttp/header.go:1698 +0x84
  github.com/valyala/fasthttp.(*RequestHeader).Write()
      D:/a/fasthttp/fasthttp/header.go:1682 +0x10f
  github.com/valyala/fasthttp.(*Request).Write()
      D:/a/fasthttp/fasthttp/http.go:1370 +0x1ab
  github.com/valyala/fasthttp.testRequestSuccess()
      D:/a/fasthttp/fasthttp/http_test.go:1788 +0x32a
  github.com/valyala/fasthttp.TestRequestSuccess()
      D:/a/fasthttp/fasthttp/http_test.go:1678 +0x2dd
  testing.tRunner()
      C:/hostedtoolcache/windows/go/1.15.15/x64/src/testing/testing.go:1123 +0x202
2021-08-28 11:54:58 +02:00
Mike Faraponov a5830066b6 Use bytes.IndexByte instead of bytes.Index for single byte lookup (#999)
* Update uri.go

* Update strings.go
2021-03-20 15:57:57 +01:00
anshul-jain-aws 6234776e7c Use QueryString while constructing RequestURI instead of QueryArgs if parsedQueryArgs is set to false (#937) 2021-01-02 21:14:25 +01:00
Vitali Pikulik aa3f96c883 Git commit fix URI parse for urls like host.dm?some/path/to/file (#866) 2020-08-21 16:21:23 +02:00
Erik Dubbelboer cc9db3ab20 Try TravisCI Windows (#828)
* Try TravisCI Windows

* prefork is supported on windows with Reuseport=true

* Bit longer timeouts for tests
2020-06-06 15:57:38 +02:00
Erik Dubbelboer 9468c66e25 URI.Parse now returns an error 2020-05-31 15:16:54 +02:00
Erik Dubbelboer 123f6a8cee Fix memory reusage bug with auth
Fixes #814
2020-05-25 20:27:15 +02:00
Erik Dubbelboer 079f39bddc Don't allow ASCII control character in URLs (#790)
* Don't allow ASCII control character in URLs

* Add tests
2020-04-25 20:54:59 +02:00
Erik Dubbelboer 76b74e34c2 Don't send the fragment/hash/# part of a URL to the server
Fixes https://github.com/valyala/fasthttp/issues/748
2020-02-28 18:56:02 +01:00
Erik Dubbelboer 6cccaebf64 Fix parsing relative URLs starting with // (#702)
* Fix parsing relative URLs starting with //

* Improve test
2019-12-01 09:44:21 +01:00
Erik Dubbelboer 32793db72d Run golangci-lint using a Github Action 2019-11-16 18:09:28 +01:00
Erik Dubbelboer d428e1b05e Fix race condition in tests, fix URI bug
- Some tests can't be run in parallel.
- `URI` had a pointer to `RequestHeader` which was updated with
`RequestHeader.CopyTo` which resulted in the URI pointing to the wrong
`RequestHeader` causing bugs and race conditions.

The only reason `URI` contained a pointer to `RequestHeader` was to delay the
call to `RequestHeader.Host()` until really needed. But these days instead
of parsing all headers, `RequestHeader.Host()` uses
`RequestHeader.peekRawHeader()` which is rather fast. So we can remove the
pointer in `URI` and completely decouple the two structs improving code
quality and fixing the bug.

For some reason this results in faster code on average as well:
benchmark                                          old ns/op     new ns/op     delta
BenchmarkClientGetEndToEnd1Inmemory-8              1189          1369          +15.14%
BenchmarkClientGetEndToEnd10Inmemory-8             1143          1161          +1.57%
BenchmarkClientGetEndToEnd100Inmemory-8            1228          1236          +0.65%
BenchmarkClientGetEndToEnd1000Inmemory-8           1213          1213          +0.00%
BenchmarkClientGetEndToEnd10KInmemory-8            1362          1350          -0.88%
BenchmarkClientEndToEndBigResponse1Inmemory-8      139967        130070        -7.07%
BenchmarkClientEndToEndBigResponse10Inmemory-8     142233        131809        -7.33%
BenchmarkServerGet1ReqPerConn-8                    1726          1593          -7.71%
BenchmarkServerGet2ReqPerConn-8                    882           927           +5.10%
BenchmarkServerGet10ReqPerConn-8                   440           436           -0.91%
BenchmarkServerGet10KReqPerConn-8                  341           339           -0.59%
BenchmarkServerPost1ReqPerConn-8                   1728          1706          -1.27%
BenchmarkServerPost2ReqPerConn-8                   968           963           -0.52%
BenchmarkServerPost10ReqPerConn-8                  506           505           -0.20%
BenchmarkServerPost10KReqPerConn-8                 424           420           -0.94%
BenchmarkServerGet1ReqPerConn10KClients-8          1117          1051          -5.91%
BenchmarkServerGet2ReqPerConn10KClients-8          565           514           -9.03%
BenchmarkServerGet10ReqPerConn10KClients-8         390           387           -0.77%
BenchmarkServerGet100ReqPerConn10KClients-8        355           348           -1.97%
BenchmarkServerHijack-8                            339           348           +2.65%
BenchmarkServerMaxConnsPerIP-8                     326           325           -0.31%
BenchmarkServerTimeoutError-8                      24355         24180         -0.72%
2019-10-19 21:02:31 +02:00
Daniel Firsht ee8450036e Added option to disable path normalization (#649) 2019-09-18 08:56:18 +02:00
Erik Dubbelboer 2edabf3b76 Add support for user:pass in URLs (#614)
Fixes #609
2019-08-18 11:23:33 +02:00
Kirill Danshin 4a16377d6e Merge pull request #303 from chebyrash/master
Typo fixes
2018-08-13 23:18:55 +03:00
Aliaksandr Valialkin e2ac397815 Parse bogus uris with missing slash after hostname like http://foobar.com?baz=123, since such uris occur in real life :( 2017-11-08 13:05:29 +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 0a7f0a797c Updated tests and documentation for URI.Parse and URI.Update* regarding uris without scheme 2017-01-09 10:50:56 +02:00
Aliaksandr Valialkin 2662f2e1f4 Allow redirecting to urls without scheme, i.e. //google.com/foo.bar 2016-08-17 18:55:32 +03:00
Aliaksandr Valialkin d055141f64 Propagate 'https' scheme to request URI for TLS connections 2016-08-17 14:01:35 +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
Aleksandr Razumov 5e1bdcae2d Issue #86: Fixed leading slash on Windows 2016-05-04 10:07:11 +03:00