Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Add support for optional default headers #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

camflint
Copy link

@camflint camflint commented Aug 1, 2016

This change adds support for default headers.

import wptserve

config = {
    "host": "localhost",
    "domains": {
        "": "localhost"
    },
    "ports": {
        "http": [8000]
    },
    # new!
    "default_headers": [
        ["Cache-Control", "no-cache, no-store"]
    ]
}

httpd = wptserve.WebTestHttpd(config=config)
httpd.start(block=True)

Default headers are useful in setting the default cache policy for wptserve when serving test files for Internet Explorer and Edge in dev and test environments, so that test files are not inadvertently cached between runs. This prevents "F5-refresh" headaches when a developer makes changes to the tests locally, and prevents leftover state on shared machines (which may need to run multiple versions of the tests) from affecting subsequent test runs.

This feature is meant to be complementary to specifying per-resource headers in .header files, header pipes, Python scripts, and so forth. Any of these explicit mechanisms will override the default headers.


This change is Reviewable

@camflint camflint changed the title Write default headers for all responses if present Server.config Add support for optional default headers Aug 1, 2016
@gsnedders
Copy link
Member

The code LGTM, and I'm in favour of the feature. I'll let others decide how much in favour of the feature they are!

@jgraham
Copy link
Member

jgraham commented Aug 1, 2016

This makes me nervous. A test that is expecting certain headers might unexpectedly fail when different headers are provided in the defaults. There's also more than one way to inadvertently store information locally so tests will fail if not run from a clean state (e.g. in local storage).

@camflint
Copy link
Author

camflint commented Aug 2, 2016

@jgraham I see where you're coming from, in that it makes sense in principle for tests to take care of their own cleanup before/after runs to minimize environmental dependencies. In the example given it's a bit of a chicken-and-egg problem, because if the browser is secretly caching test.html and I change test.html to clean up after itself and refresh the page, my new test bits aren't going loaded, and my cleanup code wouldn't run. I see the danger in using default_headers too liberally, but I do think it's useful and warranted in this scenario, and maybe some other edge cases.

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

Successfully merging this pull request may close these issues.

3 participants