Commit Graph

44 Commits

Author SHA1 Message Date
Oleksandr Redko f196617f55 chore: Use 'any' instead of 'interface{}' (#1666)
gofmt -w -r "interface{} -> any" -l .
2023-11-24 11:33:04 +01:00
Tiago Peczenyj dfce853067 Skip fs cache based on config (#1644)
* add cache manager struce

* refactor cache by adding interface

* generalize ctor

* implement feature add unit tests

* fix code

* rename fs field as filesystem
2023-11-05 19:31:04 +01:00
Oleksandr Redko a5301d9edc Replace path.Join with filepath.Join in tests (#1623) 2023-09-18 20:13:37 +02:00
Oleksandr Redko 4ec5c5a774 docs: fix typos in comments and tests 2023-08-30 14:13:13 +02:00
Oleksandr Redko ffdf59d04c Enable gofumpt linter; format code gofumpt -w . (#1576) 2023-06-13 15:18:59 +02:00
Oleksandr Redko e15a810a98 docs: fix grammar issues and typos in comments (#1492) 2023-02-13 10:43:44 +08:00
Oleksandr Redko 8dcbc41e37 test: use T.TempDir instead of MkdirTemp (#1485)
* test: use T.TempDir instead of MkdirTemp

* Fix test by adding reader.ff.Release()
2023-02-10 18:17:56 +08:00
Erik Dubbelboer dbf457ee66 Revert "feat: support mulit/range (#1398)" (#1446)
This reverts commit a468a7dd37.
2022-11-28 11:52:30 +01:00
byene0923 a468a7dd37 feat: support mulit/range (#1398)
* feat: support mulit/range

* fix:
1. lint code
2. add SetByteRanges method

* fix: reduce the test number of testFSSingleByteRange
2022-10-30 09:48:46 +01:00
Aoang a696949f6c Deprecate Go 1.15 (#1379)
* Dropping support for 1.15.

* Replaces Go 1.16 Deprecated functions

* Update test build flag

* Fix import sort and comment

* Update github.com/klauspost/compress to v1.15.9

https://github.com/klauspost/compress improved performance and changed Minimum version is 1.16, this should be the final supported release for Go 1.16 (https://github.com/klauspost/compress/commit/6d0019a95afa3221f7522d1f2eed0033b5e79470) .
2022-09-15 22:28:25 +03: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
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 7eeb00e1cc Make tests less flaky (#1189) 2022-01-10 05:15:30 +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
Erik Dubbelboer ffab77a59d Improve return value reusability documentation 2021-10-01 13:38:31 +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
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
Erik Dubbelboer 924a63fdeb Increase TestServerTLSReadTimeout timeout
And TestFSCompressConcurrent timeout
2021-06-18 15:41:42 +02:00
Erik Dubbelboer 9f2c63676d Lower go test time 2021-06-18 14:57:18 +02:00
Erik Dubbelboer 3cec26d42d Allow stopping FS handler cleanup gorountine (#942)
* Allow stopping FS handler cleanup gorountine

* CleanStop
2021-02-06 10:22:14 +01:00
hex0x00 805af0ee73 Brotli support in FS handler. (#880)
* Add files via upload

* Update fs.go

* Add files via upload

* Update fs_test.go
2020-09-28 17:14:28 +02:00
Erik Dubbelboer 4cffe1a510 Use a directory we are sure to exist for tests 2020-07-15 11:29:34 +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
Moritz Marquardt 5bd1b0cf2c Make FS return a redirect for directories without trailing slash (#802)
* Make FS return a redirect for directories without trailing slash

Fixes #792

* Add a test for the directory redirect

* Fix directory redirects for ServeFile

* Fix error message

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
2020-05-18 18:30:13 +02:00
Andy Pan 59b28fe0e5 Resolve code issues from goreportcard.com (#725) 2020-01-12 12:57:42 +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
Erik Dubbelboer c3d82ca3a4 Speed up testing by running tests in parallel 2019-10-16 10:20:13 +02:00
Maxim Lebedev d3715c361c Used Headers constants instead raw strings 2019-05-28 18:04:24 +03:00
Maxim Lebedev f544170d63 Added methods constants (#567)
*  Added methods constants

* 👌 Fixed methods comment due to review changes
2019-05-06 17:54:49 +02:00
Shulhan 9574c37fb8 Various changes regarding code readibility (#523)
* all: use sort.Strings when applicable

Basically, sort.Strings is the shortcut of Sort(StringSlice(a)) but its
more readable.

* all: replace string(bytes.Buffer.Bytes()) with bytes.Buffer.String()

Although its only occured on test files, it may be worth to simplified it.

* http_test: simplify strings.Index with strings.Contains

Both have the same O(n), but strings.Contains more readable on
if-condition.

* args: simplify if-condition check on boolean value

* all: simplify variable initialization

If we assign the variable after declaring it, we can simplify it using
":=" operator or "= value".
The reader can still known the type of variable from the struct name or
variable type before assignment operator.
2019-02-02 11:13:33 +00:00
Erik Dubbelboer d53df67945 Fix Content-Type bug in FS
Fixes #417
2018-09-20 11:36:07 +08:00
Erik Dubbelboer e3fd87a866 Added PathNotFound handle func for handling 404.
See https://github.com/erikdubbelboer/fasthttp/pull/10
2018-08-17 15:51:44 +08:00
Victor Gaydov a0fe3404bf Add test for fsSmallFileReader.WriteTo and fix bug (#128)
The bug raises when io.Writer passed to fsSmallFileReader.WriteTo
doesn't support ReadFrom interface.
2016-07-12 09:42:39 +03:00
Aliaksandr Valialkin 6c5368b250 Issue #103: Added FS.CompressedFileSuffix and clarified FSHandlerCacheDuration documentation 2016-05-24 13:22:59 +03:00
Aliaksandr Valialkin 21a70cc5b8 reduced the time required to run tests with race detector enabled 2016-02-21 13:34:55 +02:00
Aliaksandr Valialkin e72e899aa3 Issue #47: allow out-of range offsets in byte range headers according to RFC 2616 2016-02-08 16:21:49 +02:00
Aliaksandr Valialkin e0cd149b5e Enabled virtual hosting support in example fileserver 2016-02-04 17:16:43 +02:00
Aliaksandr Valialkin a208149ac4 FS optimization: do not read file contents on HEAD requests 2016-01-18 20:40:43 +02:00
Aliaksandr Valialkin 4985a4c956 Improved ServeFile* tests 2016-01-18 07:23:48 +02:00
Aliaksandr Valialkin 764a74e2ec Added ServeFile and ServeFileUncompressed to be on par with net/http 2016-01-17 23:12:38 +02:00
Aliaksandr Valialkin 8a83396595 FS: added support for byte range requests 2016-01-05 14:05:07 +02:00
Aliaksandr Valialkin 9b8a7de66b Added transparent compression option to FS 2015-12-29 11:51:11 +02:00
Aliaksandr Valialkin ebf9968b68 Renamed fshandler to fs 2015-12-09 18:52:23 +02:00