Skip to content

Commit

Permalink
Fix ETag header
Browse files Browse the repository at this point in the history
  • Loading branch information
ondratu committed Sep 8, 2024
1 parent f3d0cf6 commit f14ca59
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ parameters or as constructor argument.
return NotModifiedResponse(date=time_to_http())
return FileResponse(req.document_root+"/filename",
headers={'E-Tag': etag})
headers={'ETag': etag})
Partial Content
```````````````
Expand Down
6 changes: 3 additions & 3 deletions examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def style(_):
@app.route('/test/static')
def test_dynamic(req, variable=None):
"""Test dynamics values."""
if not variable and req.headers.get('E-Tag') == 'W/"0123"':
if not variable and req.headers.get('ETag') == 'W/"0123"':
return not_modified(req)

var_info = {
Expand Down Expand Up @@ -299,7 +299,7 @@ def test_dynamic(req, variable=None):
("</table>",) + \
get_footer()

response = Response(headers={'E-Tag': 'W/"0123"'})
response = Response(headers={'ETag': 'W/"0123"'})
for line in buff:
response.write(line + '\n')
return response
Expand Down Expand Up @@ -640,7 +640,7 @@ def simple_py(req):
if last_modified <= if_modified:
return NotModifiedResponse(date=time_to_http())

response = FileResponse(__file__, headers={'E-Tag': etag})
response = FileResponse(__file__, headers={'ETag': etag})
ranges = {}
if 'Range' in req.headers:
ranges = parse_range(req.headers['Range'])
Expand Down
2 changes: 1 addition & 1 deletion poorwsgi/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def __init__(self,

super().__init__(status_code=HTTP_NOT_MODIFIED, headers=headers)
if etag:
self.add_header('E-Tag', etag)
self.add_header('ETag', etag)
if content_location:
self.add_header('Content-Location', content_location)
if isinstance(date, str) and date:
Expand Down
4 changes: 2 additions & 2 deletions poorwsgi/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def handlers_view(handlers, sort=True):
def not_modified(req):
"""Return NotModifiedResponse.
Headers E-Tag, Content-Location is return from request.
Headers ETag, Content-Location is return from request.
Date header will be set.
"""
return NotModifiedResponse(
etag=req.headers.get('E-Tag'),
etag=req.headers.get('ETag'),
content_location=req.headers.get('Content-Location'),
date=time_to_http())

Expand Down
2 changes: 1 addition & 1 deletion tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def test_params(self):
content_location="content-location",
date="22 Apr 2022",
vary="yrav")
assert res.headers.get('E-Tag') == 'W/"etag"'
assert res.headers.get('ETag') == 'W/"etag"'
assert res.headers.get('Content-Location') == "content-location"
assert res.headers.get('Date') == "22 Apr 2022"
assert res.headers.get('Vary') == "yrav"
Expand Down
10 changes: 6 additions & 4 deletions tests_integrity/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ class TestError(RuntimeError):
"""Support exception."""


def start_server(request, example, env=None):
def start_server(request, example, env=None, close=True):
"""Start web server with example."""

process = None
print("Starting wsgi application...")
if request.config.getoption("--with-uwsgi"):
env = env or {}
env = [["--env", "=".join(items)] for items in env.items()]
env = list(chain.from_iterable(env))
params = list(chain.from_iterable(env))
if close:
params += ["--add-header", "Connection: Close"]
process = Popen(["uwsgi", "--plugin", "python3",
"--http-socket", "localhost:8080", "--wsgi-file",
example] + env)
"--http-socket", "localhost:8080",
"--wsgi-file", example] + params)
else:
# pylint: disable=consider-using-with
process = Popen([executable, example], env=env)
Expand Down
4 changes: 2 additions & 2 deletions tests_integrity/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_static(self, url):
def test_static_not_modified(self, url):
res = check_url(url+"/test/static")
check_url(url+"/test/static", status_code=304,
headers={'E-Tag': res.headers.get('E-Tag')})
headers={'ETag': res.headers.get('ETag')})

def test_variable_int(self, url):
check_url(url+"/test/123")
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_file_response_304_last_modified(self, url):

def test_file_response_304_etag(self, url):
res = check_url(url+"/simple.py")
etag = res.headers.get('E-Tag')
etag = res.headers.get('ETag')
res = check_url(url+"/simple.py",
headers={'If-None-Match': etag},
status_code=304)
Expand Down
3 changes: 2 additions & 1 deletion tests_integrity/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def server(request):

process = start_server(
request,
join(dirname(__file__), pardir, 'examples/websocket.py'))
join(dirname(__file__), pardir, 'examples/websocket.py'),
close=False)

yield "localhost:8080" # server is running
process.kill()
Expand Down

0 comments on commit f14ca59

Please sign in to comment.