Commit Graph

50 Commits

Author SHA1 Message Date
Laurence Withers 5398dddb02 Add --graceful-shutdown-delay
This option allows a configurable delay after receiving SIGTERM (or
SIGINT) but before the HTTP server stops accepting new connections. It
is quite useful for distributed systems where callers are only notified
asynchronously (e.g. via service discovery) that a service is being shut
down; it prevents the shut down from occurring prior to callers
processing the notification.

This required some minor refactoring to allow the Shutdown() method on
http.Server to be accessed.
2022-11-26 10:43:18 +00:00
Laurence Withers e0ae6bb4b6 cmd/packserver: update to Go 1.19, update dependencies 2022-11-26 10:14:25 +00:00
Laurence Withers 6b836895a0 cmd/htpacker: update to Go 1.19, update dependencies 2022-11-26 10:12:42 +00:00
Laurence Withers 301dc0c7c8 Update to Go 1.19 2022-11-26 10:08:16 +00:00
Laurence Withers a6c2991781 cmd/htpacker: updated dependencies 2022-07-06 13:31:22 +01:00
Laurence Withers d827d8aace cmd/htpacker: add --content-type flag
This allows overriding the content-type of files being packed using the
ad-hoc method (not YAML spec).
2022-07-06 13:29:55 +01:00
Laurence Withers 565a269cef cmd/packserver: add --frames option
Allows override of the X-Frame-Options header on the handler.
2022-07-06 10:33:54 +01:00
Laurence Withers 16d836da9a cmd/packserver: dependency update 2022-07-06 10:17:32 +01:00
Laurence Withers 8cae4d0f8f Correct X-Frame-Options value sameorigin→SAMEORIGIN 2022-07-06 10:15:28 +01:00
Laurence Withers 6ea49bb3b3 Updated dependencies 2022-07-06 10:00:24 +01:00
Laurence Withers 83a5226e1a handler: drop sendfile(2) support
After some experimentation, I found that the sendfile(2) support did not
really save any time compared to just write(2) from an already
memory-mapped file.

After some reading, I think open/sendfile is supposed to be slightly
more efficient than open/mmap/write — but if we already did the mmap
step, then it doesn't save us much.

Moreover, the code to support sendfile(2) is a bit icky, and also forces
us to close the HTTP connection after serving a file.
2022-07-06 09:53:34 +01:00
Laurence Withers 1b84160dcf cmd/htpacker: cope with zero-length input files
Sometimes we might be asked to serve up a zero-length input file,
typically from some machine-generated CSS etc. We make some very
rudimentary guess about the content-type the caller wanted and skip the
mmap(2) call.
2020-04-02 12:33:04 +01:00
Laurence Withers 52213cf67e cmd/htpacker: report filename on I/O error 2020-04-02 12:25:23 +01:00
Laurence Withers f70914aa38 cmd/packserver: add --fallback-404 arg for Angular-style SPA support 2020-02-15 12:35:05 +00:00
Laurence Withers ca54fb8fbb Add doc link to README.md 2020-02-15 12:27:45 +00:00
Laurence Withers d5b4fcf0be Implement library support for Angular-style single page applications 2020-02-15 12:26:01 +00:00
Laurence Withers f08165b0f1 Update README to remove reference to external brotli command
Since we're now using github.com/andybalholm/brotli to natively pack, there's no need to refer
to an external brotli process any more.
2020-02-15 11:23:42 +00:00
Laurence Withers 6f532296ef Add CLI progress bars to the packer tool
Since packing can be quite slow, it is nice to display progress to the
caller. We use the excellent github.com/vbauerster/mpb library to do so,
and add a bit of colour with github.com/logrusru/aurora.

Finally, augment the inspector and packer with a summary printer that
displays the overall file size/count, and compression ratio for each
compression type.
2020-02-15 11:22:24 +00:00
Laurence Withers 984639d475 Finish porting child modules to src.lwithers.me.uk 2020-01-15 18:36:05 +00:00
Laurence Withers 1a37903d98 Add MIT licence file 2020-01-15 18:31:11 +00:00
Laurence Withers 7abc96d537 Moved module to src.lwithers.me.uk 2020-01-15 18:28:43 +00:00
Laurence Withers 280bf2b181 brotli CLI no longer takes --input argument 2019-12-10 15:03:41 +00:00
Laurence Withers 566c23dd7e cmd/packserver: bump to latest version of handler
Adds range support.
2019-10-09 13:06:02 +01:00
Laurence Withers f7cd22f633 Single range support
We now support single part ranges, as per:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests#Single_part_ranges

Multi-part ranges are not implemented because there have been far too
many bugs in this area.

It interacts with compression by selecting a byte range from the
compressed stream. Since the compressed stream is fixed, the results are
consistent.
2019-10-09 13:04:07 +01:00
Laurence Withers 8fc082c4ca cmd/packserver: build against latest mod, go mod tidy 2019-07-17 16:31:43 +01:00
Laurence Withers b7b5dd55d0 Remove stray debug printf 2019-07-17 16:30:20 +01:00
Laurence Withers b6da0b4e48 cmd/htpacker: update dependendencies 2019-06-25 15:32:24 +01:00
Laurence Withers 0883b0b405 cmd/htpacker: workaround for SVG files without XML prolog
If a .svg file doesn't have a “<?xml…” prolog, then it would be detected as plain
text. Allow extension-based override of the content-type in this case.
2019-06-25 15:31:49 +01:00
Laurence Withers 8528a31d54 cmd/packserver: bump htpack dependency 2019-05-28 13:00:02 +01:00
Laurence Withers c2d7bdaa71 handler: fix sendfile to be non-blocking
Having done a bit more research on exactly how to use sendfile()
effectively with Go's own event loop, we can now leave the HTTP socket
in non-blocking mode and correctly integrate with the event loop to wait
for the socket to be writeable once more.
2019-05-28 12:57:59 +01:00
Laurence Withers 97a823d748 packserver: use htpack v1.1.1 2019-05-10 13:22:53 +01:00
Laurence Withers eac79eb605 Set blocking mode on hijacked fds for sendfile 2019-05-10 13:21:22 +01:00
Laurence Withers 21a18eced6 cmd/packserver: use Cache-Control: no-cache
Rather than setting "Cache-Control: no-store", use "no-cache". The
difference is that "no-store" tells the browser that it must always
completely re-fetch the resource; whereas "no-cache" means that the
browser can write the resource to disk but must re-validate it (e.g.
using Etags) before re-using it.
2019-04-25 14:47:13 +01:00
Laurence Withers 246aefbec4 cmd/packserver: add --index-file argument 2019-04-25 14:45:18 +01:00
Laurence Withers be86cbaed3 Handler: add SetIndex
This allows setting an index.html (or equivalent) filename; this means that
we can serve requests to "/foo" with the contents of "/foo/index.html".
2019-04-25 14:17:55 +01:00
Laurence Withers e28f687057 cmd/htpacker, cmd/packserver: update dependencies 2019-04-15 14:19:12 +01:00
Laurence Withers 5328627998 Update dependencies 2019-04-15 14:15:43 +01:00
Laurence Withers 527b361b51 Finish up the initial packserver implementation 2019-04-15 14:10:26 +01:00
Laurence Withers ea77f42dc3 Note a TODO in the README 2019-04-12 09:16:23 +01:00
Laurence Withers e47ed4e4c2 cmd/htpacker now split into its own module 2019-04-12 09:15:28 +01:00
Laurence Withers ce6749f0a3 Workaround for splitting to multiple modules 2019-04-12 09:14:21 +01:00
Laurence Withers fdd1990e89 Reorganise ready to split into modules 2019-04-12 09:07:17 +01:00
Laurence Withers 84ea7c3673 cmd/htpacker: lots more WIP 2019-03-29 09:18:07 +00:00
Laurence Withers feb25bf276 Handler: close TCP conn after Sendfile
Since we hijacked the HTTP connection, we need to close the underlying TCP
connection after calling Sendfile.
2019-03-29 09:17:46 +00:00
Laurence Withers d42094ea72 Handler: call path.Clean first
Cope with things like /foo//bar by calling path.Clean before searching for
path in the map.
2019-03-29 09:17:15 +00:00
Laurence Withers 5c05a75fba Further work; tidying up, begin cmdline tool 2019-03-13 21:55:31 +00:00
Laurence Withers 2a25d80249 Handler implementation
Currently missing range support, but compression and etag processing is
in along with basic header support. Still needs unit tests.
2019-03-08 09:16:38 +00:00
Laurence Withers d836bf3cc7 Further work-in-progress, basic packing and inspecting 2019-03-05 18:41:02 +00:00
Laurence Withers e864d0829e Basic work-in-progress, can pack basic files now 2019-02-24 12:17:57 +00:00
Laurence Withers 0fc26e5414 Initial README 2019-02-23 13:47:59 +00:00