Commit Graph

58 Commits

Author SHA1 Message Date
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
Shulhan 4c53f113c5 all: pre-allocated slice with possible known size
This fix is based on suggestion of "prealloc" static analysis tool [1].

Per note of the tool's author suggestion, its recommended to allocate the
slice length/capability, if we known their possible size.  This is to
minimize "append" to re-allocate the slice underlying array.

[1] https://github.com/alexkohler/prealloc
2019-01-30 20:42:28 +01:00
Erik Dubbelboer d4f0cf56d8 Remove fasthttp.ByteBuffer
As advertised in https://github.com/valyala/fasthttp/commit/b5f96d4b4120bb1e09c23ac32baf21a14da4a71d
2018-10-01 14:15:29 +08:00
Erik Dubbelboer d53df67945 Fix Content-Type bug in FS
Fixes #417
2018-09-20 11:36:07 +08:00
Jerry Jacobs 6025a4a41c Allow overwrite of ContentType by caller of RequestCtx.ServeFile 2018-09-13 12:27:17 +08:00
Kirill Danshin dc5b83b915 fs/pathNotFound: do not overwrite user's status code
Signed-off-by: Kirill Danshin <k@guava.by>
2018-08-17 22:04:50 +03: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
xPushkin f24d00fcc6 A lot of typo fixes 2017-10-08 13:30:35 +01:00
Aliaksandr Valialkin 30e92af08f Limit heap memory usage when compressing high number of concurrent responses
Previously each concurrent compression could allocate huge compression state
with the size up to 1Mb each. So 10K concurrent connections could result in
10Gb of compression state in the heap.

This CL limits the number of compression states among concurrent requests
when {Append,Write}{Gzip,Deflate}* functions are called to O(GOMAXPROCS).
These functions are used by CompressHandler* for non-streaming responses,
i.e. it should cover the majority of use cases.

Memory usage for 10K concurrent connections that compress responses drops
from 10Gb to 200Mb after this CL.
2017-05-17 14:45:31 +03:00
Aliaksandr Valialkin 204fed9187 Revert "Use standard compress packages until https://github.com/klauspost/compress/issues/64 is fixed"
The original issue has been fixed, so reverting.

This reverts commit 2f4876aaf2.
2016-10-20 18:02:21 +03:00
Aliaksandr Valialkin 2f4876aaf2 Use standard compress packages until https://github.com/klauspost/compress/issues/64 is fixed 2016-10-20 15:30:15 +03:00
Aliaksandr Valialkin b131f05f50 Revert "Use standard compress/* packages instead of github.com/klauspost/compress/*"
According to @klauspost, his packages are still faster than the standard packages.
See https://github.com/valyala/fasthttp/commit/a98191f43560ea2ddbbf848c1c727daeed2e39ae#commitcomment-19409416
for details.

This reverts commit a98191f435.
2016-10-13 14:57:35 +03:00
Aliaksandr Valialkin a98191f435 Use standard compress/* packages instead of github.com/klauspost/compress/*
The reasons are:
- @klauspost optimized standard packages in go1.7+
- This removes an external dependency from fasthttp
2016-10-13 13:01:51 +03: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 0d43464f64 Renamed unsafeBytes2Str to b2s 2016-03-29 16:26:21 +03:00
Aliaksandr Valialkin 9ad70994bb code cleanup: removed duplicate code in fs.go 2016-03-21 18:42:34 +02:00
Aliaksandr Valialkin 76e0faee32 Added anti-copy guard to FS type 2016-03-06 19:12:00 +02:00
Aliaksandr Valialkin 3e83cf1c27 Properly handle missing file error in ServeFile 2016-02-29 14:45:42 +02:00
Aliaksandr Valialkin 68c6a4f496 Added ServeFileBytes* and RequestCtx.SendFileBytes* helper functions 2016-02-29 14:42:55 +02:00
Aliaksandr Valialkin 9f608dd1fd Issue #51: Make RequestCtx.SendFile a synonim to ServeFile. This breaks RequestCtx.SendFile API, but I believe the new behaviour of SendFile outweights API breakage 2016-02-17 11:35:36 +02:00
Aliaksandr Valialkin 87628147e5 Use zero-alloc copy instead of io.Copy 2016-02-13 11:01:18 +02:00
Aliaksandr Valialkin 9c9b5abffa Documentation update according to golint 2016-02-12 17:47:57 +02:00
Aliaksandr Valialkin 80368e6491 Switch from bytes.Buffer to ByteBuffer where appropriate 2016-02-12 14:07:56 +02:00
Aliaksandr Valialkin 0aec76fa1f code cleanup 2016-02-11 19:32:38 +02:00
Aliaksandr Valialkin 8757b644eb Exported ByteBuffer 2016-02-11 12:12:37 +02:00
Aliaksandr Valialkin bb2a414fe8 Issues #14, #46: use @klauspost 's compress library instead of standard compress/*, since it provides better performance on average 2016-02-10 16:40:14 +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 913d03cc84 Do not allocate memory when constructing path inside VHostPathRewriter 2016-02-05 13:00:52 +02:00
Aliaksandr Valialkin e0cd149b5e Enabled virtual hosting support in example fileserver 2016-02-04 17:16:43 +02:00
Aliaksandr Valialkin 5dff324211 FS: verify that the path doesn't contain '/../' only if PathRewriter is used 2016-02-04 16:44:07 +02:00
Aliaksandr Valialkin f36c218b13 FS: make sure that the path returned from PathRewriteFunc doesn't contain '/../' due to security reasons 2016-02-04 16:38:24 +02:00
Aliaksandr Valialkin 33e5464e41 fs: allow multiple calls to FS.NewRequestHandler() 2016-02-03 11:07:45 +02:00
Aliaksandr Valialkin b127e96399 FS: reset response body on HEAD request 2016-01-20 13:27:22 +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 764a74e2ec Added ServeFile and ServeFileUncompressed to be on par with net/http 2016-01-17 23:12:38 +02:00
Aliaksandr Valialkin 414149027d gofmt 2016-01-08 13:39:51 +02:00
Aliaksandr Valialkin 56a0483095 FS: limit maximum file size, which can be compressed 2016-01-08 12:57:42 +02:00
Aliaksandr Valialkin bbb68f32d1 FS: reduced miminum compression ratio for triggering response compression. This should reduce CPU usage for files with low compression ratio 2016-01-08 12:52:35 +02:00
Aliaksandr Valialkin da62899f14 Removed obsolete startPos verification 2016-01-05 14:22:17 +02:00
Aliaksandr Valialkin 8a83396595 FS: added support for byte range requests 2016-01-05 14:05:07 +02:00
Aliaksandr Valialkin 4bca54c0bb Issue #29: use time.UTC instead of time.LoadLocation, since this call may fail on systems without certain config files 2016-01-04 15:55:30 +02:00
Aliaksandr Valialkin 8b38f99229 FS: correctly detect content-type for transparently compressed files 2015-12-30 15:27:54 +02:00
Aliaksandr Valialkin c20fff55a6 FS: detect file content-type with net/http.DetectContentType if the type cannot be determined by file extension 2015-12-30 15:13:50 +02:00
Aliaksandr Valialkin 0d58868d33 FS: do not show compressed files ending with .fasthttp.gz in automatically generated directory index 2015-12-30 14:39:39 +02:00
Aliaksandr Valialkin 58ff6e004c code cleanup: removed unused pendingFiles member from fsHandler 2015-12-30 13:36:33 +02:00
Aliaksandr Valialkin b28a765ded Emit log warning if FS request handler has no permissions for creating compressed file 2015-12-29 12:14:50 +02:00
Aliaksandr Valialkin 9b8a7de66b Added transparent compression option to FS 2015-12-29 11:51:11 +02:00
Aliaksandr Valialkin d2db95337f Removed 'v interface{}' hack from structs managed via sync.Pool, since it has no sense 2015-12-23 11:39:40 +02:00
Aliaksandr Valialkin d54fa3f450 FS: parent path fix 2015-12-20 02:15:23 +02:00