Commit Graph

1419 Commits

Author SHA1 Message Date
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
Sergey Ponomarev 8febad0797 http.go: Request.SetURI() (Fix #1141) (#1148)
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-11-08 13:09:35 +01:00
Shivansh Vij 2ca01c7efb fix: Status Line parsing and writing (#1135)
* Adding zero-allocation uint64 to byte slice conversion and fixing the ResponseHeader.SetStatusLine function call signature

* Removing unnecessary i2b function

* Fixing various bugs

* Adding test cases

* Commenting AppendStatusLine

* Update status.go

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

* Update header.go

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

* Cleaning up references to strHTTP11, using formatStatusLine for invalidStatusLine, and making `appendStatusLine` an unexported function

Issue: https://github.com/valyala/fasthttp/issues/1132

* Fixing merge conflicts

Issue: https://github.com/valyala/fasthttp/issues/1132

* Replacing []byte{} with nil in some test cases

Issue: https://github.com/valyala/fasthttp/issues/1132

* Cleaning up parsing first line, and improving StatusMessage function

Issue: https://github.com/valyala/fasthttp/issues/1132

* Fixing as per PR

* Update header.go

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

* Update header.go

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

* Fixing as per requested changes

* Update header_test.go

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

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2021-11-08 09:44:02 +01:00
Erik Dubbelboer 931d0a4523 Fix lint 2021-11-04 13:24:40 +01:00
halst d613502912 use sync.map is better (#1145)
* use sync.map is better

* Use LoadOrStore
2021-11-04 13:01:58 +01:00
Erik Dubbelboer c15e642a16 Don't run all race tests on windows (#1143)
* Don't run all race tests on windows

It's too slow and gives a lot of false positives in our tests.

* No FS tests on windows
2021-10-31 22:09:40 +01:00
tyltr 6006c8761d chore (#1137) 2021-10-30 15:58:20 +02:00
Erik Dubbelboer 6d4db9bb7e Fix race condition in getTCPAddrs 2021-10-29 20:24:17 +02:00
Shivansh Vij 528dd62239 feat: ability to read body separate from header (#1130)
* 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-22 21:00:40 +02:00
Valentin Paz Marcolla 556aa814e4 feat: ability to edit status messages (#1126)
* SetStatusMessage

* Docstring

* statusLine in header

* Use statusLine as []byte + ResponseHeader parsing

* status line getter
2021-10-22 17:53:35 +02:00
Sergio VS 4cfec1a795 feat: make public Server.TLSConfig (#1128)
* feat: make public Server.TLSConfig

* fix: clone tls config only when ServeTLS, ServeTLSEmbed, ListenAndServeTLS or ListenAndServeTLSEmbed
2021-10-20 20:41:02 +02:00
tyltr fe7d90ed50 remove redundant code (#1127) 2021-10-19 12:47:55 +02:00
Erik Dubbelboer 81fc968270 Add warning to readme v1.31.0 2021-10-09 20:39:05 +02:00
tyltr 7fdd5261e8 feat: a new userData API Remove (#1117)
* feat:userData new api "delete"

* ctx api `remove`

* rename

* modify
2021-10-08 17:45:45 +02:00
tyltr f307299246 feat:no need to store nil (#1116)
* feat:no  need  to  store nil

* lint
2021-10-06 18:03:16 +02: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
tyltr 711e421685 feat: improve TCPDialer by sync.map instead of map+mutex (#1106) 2021-09-20 16:44:32 +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
tyltr 44d0333ba3 fix: typo (#1105) 2021-09-17 09:16:52 +02:00
Evgenii 06b464f084 fix typo in deadline (#1099) 2021-09-11 12:05:40 +02:00
Erik Dubbelboer 46d92356a8 Check go fmt during lint (#1097) 2021-09-10 18:49:45 +02:00
Kyle Unverferth 713da4e33f Adding new compressible prefixes (#1092)
* Adding "image/svg" as compressible prefix

* Adding additional compressible prefixes from https://support.cloudflare.com/hc/en-us/articles/200168396-What-will-Cloudflare-compress-
v1.30.0
2021-09-07 10:03:41 +02:00
tyltr 1647255ec9 remove unnecessary op (#1095) 2021-09-07 09:40:13 +02:00
tyltr f0a21893b9 feat: improve IsMethod (#1088)
* feat: improve bytesEqual

* benchmark

* nolint:unused

* remove unused  code

* Update client.go

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

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2021-09-06 12:06:21 +02:00
Mikhail Faraponov 5d73da31ae Update status.go (#1093) 2021-09-06 09:43:29 +02:00
Erik Dubbelboer 3f70d780be Some FS tests can't run in parallel
These tests all try to create the compressed versions of files at the
same time which might lead to concurrency errors.
2021-09-05 10:45:21 +02:00
tyltr ba401075d3 compatible with new build tag (#1087) 2021-09-02 00:18:53 +02:00
tyltr d9c75732a6 improve invalidStatusLine by appending a []byte directly (#1086)
* improve invalidStatusLine

* append []byte directly

* AppendUint

* negetive

* AppendInt
2021-09-01 19:27:14 +02:00
Andy Pan cad867ad92 Remove the redundant badage (#1085) 2021-09-01 12:28:46 +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
Erik Dubbelboer 63211032d4 Various deadline fixes (#1081) 2021-08-28 11:19:32 +02:00
Erik Dubbelboer 51508d7480 Fix various Windows Github Action errors (#1082)
* Fix various Windows Github Action errors

These tests keep giving errors because Windows Actions are slower.

* Remove some timeouts

We don't need timeouts in all tests, only in the ones where we are
actually testing timeout logic.
2021-08-28 09:42:38 +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
Erik Dubbelboer a50f59be52 Increase various test timeouts
Github workers on windows are slow.
2021-08-24 11:18:22 +02:00
Lanco 0fe8cddd97 Optimize size of Server by moving bool fields (#1077) 2021-08-23 11:27:51 +02:00
Erik Dubbelboer a6f9c8a442 Fix Client doc and mCleaner (#1076)
- Reduce mCleaner goroutine time.
- Add comment about changing Client fields while in use.
2021-08-20 14:52:06 +02:00
Erik Dubbelboer 5a6e6e102b Add Go 1.17 support (#1074)
* Add Go 1.17 support

* Increase test timeouts
2021-08-18 21:38:21 +02:00
Mikhail Faraponov 97e1319927 Update compress (#1069) v1.29.0 2021-08-16 18:09:31 +02:00
Erik Dubbelboer 0263cae5a2 Fix FasthttpSocksDialer example 2021-08-14 10:28:45 +02:00
Tianyi Song d31e6dbdba Handle perIPConn in RequestCtx.IsTLS() specially (#1064) 2021-08-04 20:15:05 +02:00
Kazumasa Takenaka (Bamboo) 9466cd7657 fix typo: occured -> occurred (#1061) 2021-07-17 17:51:59 +02:00
Darío b3ece39dcd Update README.md (#1058) 2021-07-08 09:55:08 +02:00
Sujit Baniya d0df1e1dde Add ResetUserValues() and test (#1056) 2021-07-01 10:57:21 +02:00
Erik Dubbelboer 1504a84ed7 Increase TestHostClientMaxConnWaitTimeoutSuccess timeout v1.28.0 2021-06-29 09:36:30 +02:00
Erik Dubbelboer f6560bebb2 Flush buffered responses if we have to wait for the next request (#1050)
* Flush buffered responses if we have to wait for the next request

Don't wait for the next request as this can take some time, instead
flush the outstanding responses already.

Fixes #1043

* Only peek 1 byte

Make sure old clients that send bogus \r\n still work.
See: https://github.com/golang/go/commit/bf5e19fbaf02b1b25fbe50c27ec301fe830a28d0
2021-06-28 17:38:39 +02:00
Erik Dubbelboer 874c8cad76 Increase timeouts for Windows github actions v1.27.0 2021-06-18 15:46:40 +02:00
Erik Dubbelboer 924a63fdeb Increase TestServerTLSReadTimeout timeout
And TestFSCompressConcurrent timeout
2021-06-18 15:41:42 +02:00
Erik Dubbelboer 410bde6009 Fix race condition in TestPipelineClientIssue832 2021-06-18 15:28:58 +02:00