max-age = 1 week for everything
stale-while-revalidate = 1 day for everything except raw pastes
immutable for raw pastes
Most likely fixes#2, unless I forgot something.
Suggested-by: Leonora Tindall <ltindall@fastly.com>
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
In order to support custom headers for various response types,
this commit adds a wrapper type, ResponseWrapper, which can service
all types of response in `bin`.
For paste objects, the preferred `Last-Modified` is used, so that caches
can compare their exact timings with the HEAD response when
revalidating.
For static objects, an `ETag` is used instead, based on the Cargo version
and git hash of the codebase at compilation time; a `build.rs` is used
for this.
Previously, uploading a paste with invalid UTF-8 and then viewing it
with the pretty URL would cause a panic.
With this change, it simply redirects to the raw URL.
Templating is weird af in Rocket. Look into 3a541ae for more.
The content-type of the rendering is determined by the extension of the
template name.
But renaming these templates would break building the project for
development because it finds a phony template there. So the trick is to
default the `template_dir` to `args.upload` because it should never
interfere and will be always present.
This also fixes the hax in Dockerfile by making it the default.
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
Rocket's templating is not exactly friendly when it comes to embedding
in-binary. Rocket's template fairing requires a `template_dir` directory
pointing to the directory containing templates.
A quick workaround to this would be to have custom fairings with
`template_dir` merged with the value `.`
But in bare-metal scenarios like what docker's scratch image mimics, we
don't exactly have a '.' file, so instead for this very project, I have
to point the `template_dir` to the `upload` folder, which is created by
`bin` on execution. Checkout the Dockerfile for more info
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
cleaned up code and added a route for signifying code language
explicitly at `/p/<filename>.<ext>`
Also async-ified the server after upgrading Rocket to 0.5-rc1
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
Getting into frontend biz.
Also s/HOST/HOST_URL/ because I didn't realise that HOST is already a
taken variable.
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
cpp files were getting recognised as "text/csrc". checking subtrings is
a better way to compare MIME types.
Signed-off-by: Gunwant Jain <mail@wantguns.dev>