Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .headers support #360

Open
BigBlueHat opened this issue Apr 25, 2017 · 5 comments
Open

Add .headers support #360

BigBlueHat opened this issue Apr 25, 2017 · 5 comments

Comments

@BigBlueHat
Copy link
Member

The .headers file idea comes from the File Handler in wptserve (a Python-based server for running the Web Platform Tests system at the W3C).

They look like this:

Content-Type: text/html

In wptserve they can be associated with single files (index.html.headers or index.headers) as well as directories (for /about/ style requests) via a __dir__.headers file (because Python-esque).

The advantage is that you can then provide any number of HTTP headers for any file or "directory" or perhaps even non-resource requests such as handling HEAD-only requests or 303 See Also specific entities.

This could be used to address a number of issues related mentioned here related to caching and content-types as well as things like advanced CORS and CSP handling.

Thoughts welcome!

@nbarbettini
Copy link

I'd love to see this merged into http-server. It's harder than I expected to find a simple Node HTTP server that lets me set custom headers easily.

@LvChengbin
Copy link

I am sorry, I cannot understand how to use it. I added a .headers file under the dir, but it doesn't work.

@BigBlueHat
Copy link
Member Author

@LvChengbin it's not implemented yet, but there seems to be enough interest in it to do the work now.

@nbarbettini thanks for the +1. I'd been a bit concerned that this changed the nature of http-server a bit, but given that these are optional files that augment requests, I think it's fine--though I'll still probably put it behind an optional command line flag to avoid the double-disk checking for each request if it's not in use.

@BigBlueHat
Copy link
Member Author

Netlify uses a top-level _headers file with path mapping:
https://www.netlify.com/docs/headers-and-basic-auth/

Having the header files closer to the actual requested file seems better, but a single top-level file does avoid the double-file disk reads per each request (so that's a good).

@aggregate1166877
Copy link

Out of desperation I've forked all this and merged hedefalk's 7 year old version with the latest stuff here.

It's a temporary hack solution and I'm likely not going to merge future changes into that, so it's officially unmaintained, but it's a workaround for the desperate like me until the authors merge in hedefalk's changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants