Skip to content

Commit

Permalink
Honor Content-Type in .headers files. (#103)
Browse files Browse the repository at this point in the history
r=gsnedders
  • Loading branch information
Ms2ger authored and gsnedders committed Sep 27, 2016
1 parent 4432c5f commit 071c51e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/functional/docroot/with_headers.txt.sub.headers
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Another-Header: {{$id:uuid()}}
Same-Value-Header: {{$id}}
Double-Header: PA
Double-Header: SS
Content-Type: text/html
1 change: 1 addition & 0 deletions tests/functional/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_GET(self):
def test_headers(self):
resp = self.request("/with_headers.txt")
self.assertEqual(200, resp.getcode())
self.assertEqual("text/html", resp.info()["Content-Type"])
self.assertEqual("PASS", resp.info()["Custom-Header"])
# This will fail if it isn't a valid uuid
uuid.UUID(resp.info()["Another-Header"])
Expand Down
12 changes: 6 additions & 6 deletions wptserve/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,12 @@ def __call__(self, request, response):
raise HTTPException(404)

def get_headers(self, request, path):
rv = self.default_headers(path)
rv.extend(self.load_headers(request, os.path.join(os.path.split(path)[0], "__dir__")))
rv.extend(self.load_headers(request, path))
rv = (self.load_headers(request, os.path.join(os.path.split(path)[0], "__dir__")) +
self.load_headers(request, path))

if not any(key.lower() == "content-type" for (key, _) in rv):
rv.insert(0, ("Content-Type", guess_content_type(path)))

return rv

def load_headers(self, request, path):
Expand Down Expand Up @@ -206,9 +209,6 @@ def get_range_data(self, f, byte_range):
f.seek(byte_range.lower)
return f.read(byte_range.upper - byte_range.lower)

def default_headers(self, path):
return [("Content-Type", guess_content_type(path))]


file_handler = FileHandler()

Expand Down

0 comments on commit 071c51e

Please sign in to comment.