Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serving: absolute request URLs need a scheme #890

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Werkzeug Changelog
==================

Version 0.11.6
--------------

- werkzeug.serving: Fix broken HTTP_HOST when path starts with double slash.

Version 0.11.5
--------------

Expand Down
35 changes: 35 additions & 0 deletions tests/test_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
except ImportError:
watchdog = None

try:
import httplib
except ImportError:
from http import client as httplib

import requests
import requests.exceptions
import pytest
Expand All @@ -39,6 +44,36 @@ def test_serving(dev_server):
assert b'Werkzeug/' + version.encode('ascii') in rv


def test_absolute_requests(dev_server):
server = dev_server('''
def app(environ, start_response):
assert environ['HTTP_HOST'] == 'surelynotexisting.example.com:1337'
assert environ['PATH_INFO'] == '/index.htm'
addr = environ['HTTP_X_WERKZEUG_ADDR']
assert environ['SERVER_PORT'] == addr.split(':')[1]
start_response('200 OK', [('Content-Type', 'text/html')])
return [b'YES']
''')

conn = httplib.HTTPConnection(server.addr)
conn.request('GET', 'http://surelynotexisting.example.com:1337/index.htm#ignorethis',
headers={'X-Werkzeug-Addr': server.addr})
res = conn.getresponse()
assert res.read() == b'YES'


def test_double_slash_path(dev_server):
server = dev_server('''
def app(environ, start_response):
assert 'fail' not in environ['HTTP_HOST']
start_response('200 OK', [('Content-Type', 'text/plain')])
return [b'YES']
''')

r = requests.get(server.url + '//fail')
assert r.content == b'YES'


def test_broken_app(dev_server):
server = dev_server('''
def app(environ, start_response):
Expand Down
2 changes: 1 addition & 1 deletion werkzeug/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def shutdown_server():
if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'):
environ[key] = value

if request_url.netloc:
if request.scheme and request_url.netloc:
environ['HTTP_HOST'] = request_url.netloc

return environ
Expand Down