Skip to content

Commit

Permalink
serve: get params and fragments should be ignored (#80)
Browse files Browse the repository at this point in the history
fixes #79
  • Loading branch information
moggers87 committed Apr 9, 2020
1 parent e52f8d0 commit 77b2c56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions exhibition/tests/test_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ def test_fetch_file(self):
headers = dict(response.getheaders())
self.assertEqual(headers["Cache-Control"], "no-store")

def test_fetch_file_with_get_params(self):
settings = Config({"deploy_path": self.tmp_dir.name, "content_path": self.tmp_dir.name})
self.get_server(settings)

self.client.request("GET", "/style.css?something=1")
response = self.client.getresponse()
self.assertEqual(response.status, 200)
content = response.read()
self.assertEqual(content, CSS_CONTENTS.encode())
headers = dict(response.getheaders())
self.assertEqual(headers["Cache-Control"], "no-store")

def test_fetch_file_with_fragment(self):
settings = Config({"deploy_path": self.tmp_dir.name, "content_path": self.tmp_dir.name})
self.get_server(settings)

self.client.request("GET", "/style.css#something")
response = self.client.getresponse()
self.assertEqual(response.status, 200)
content = response.read()
self.assertEqual(content, CSS_CONTENTS.encode())
headers = dict(response.getheaders())
self.assertEqual(headers["Cache-Control"], "no-store")

def test_fetch_file_with_prefix(self):
settings = Config({"deploy_path": self.tmp_dir.name, "content_path": self.tmp_dir.name,
"base_url": "/bob/"})
Expand Down
2 changes: 2 additions & 0 deletions exhibition/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def gen(settings):
class ExhibitionBaseHTTPRequestHandler(SimpleHTTPRequestHandler):
def _sanitise_path(self, path):
""" Strip leading and trailing / as well as base_url, if preset """
path = path.split('?', 1)[0]
path = path.split('#', 1)[0]
path = path.strip("/")
if self._settings.get("base_url"):
base = self._settings["base_url"].strip("/")
Expand Down

0 comments on commit 77b2c56

Please sign in to comment.