dhttpd
dhttpd copied to clipboard
Add support for header files.
Description
The current option for customizing response headers is very limited, as demonstrated by #63 and #22. This pull request adds the possibility of specifying path-specific headers using a file (with the new --headersfile option).
Design
The goal is to enable the possibility of testing complex headers behavior in a local environment. To this end, I have focused on adding support for two "real-world" header file formats:
- A JSON format used by Firebase Hosting.
- A plain text format used by Netlify and Cloudflare Pages.
Each of these formats uses a glob pattern-mathing system to specify the paths to which the headers should be applied. Additional file formats could be added in the future with minimal effort.
Additional notes
- I have added a new dependency to the project: glob. This package is used to match the paths in the header files.
- I have added a new test:
headers_test.dart. It tests header parsing. - I have added two example header files:
sample/_headersandsample/headers.json. These files are also used in the tests. - I have taken the liberty of including PR #63, as it is a very small change and it is closely related.