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

Add host property to Request #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions brubeck/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _parse_mime_body(self, boundary, data, arguments, files):
if boundary.startswith('"') and boundary.endswith('"'):
boundary = boundary[1:-1]
if data.endswith("\r\n"):
footer_length = len(boundary) + 6
footer_length = len(boundary) + 6
else:
footer_length = len(boundary) + 4
data = str(data)
Expand All @@ -85,7 +85,7 @@ def _parse_mime_body(self, boundary, data, arguments, files):
if not part:
continue
eoh = part.find("\r\n\r\n")
if eoh == -1:
if eoh == -1:
logging.warning("multipart/form-data missing headers")
continue
#headers = HTTPHeaders.parse(part[:eoh].decode("utf-8"))
Expand All @@ -101,8 +101,8 @@ def _parse_mime_body(self, boundary, data, arguments, files):
name, value = line.split(":", 1)
last_key = "-".join([w.capitalize() for w in name.split("-")])
headers[name] = value.strip()
disp_header = headers.get("Content-Disposition", "")

disp_header = headers.get("Content-Disposition", "")
disposition, disp_params = self._parse_header(disp_header)
if disposition != "form-data" or not part.endswith("\r\n"):
logging.warning("Invalid multipart/form-data")
Expand Down Expand Up @@ -134,7 +134,7 @@ def _parseparam(self, s):

def _parse_header(self, line):
"""Parse a Content-type like header.

Return the main content-type and a dictionary of options.
"""
parts = self._parseparam(';' + line)
Expand All @@ -149,7 +149,7 @@ def _parse_header(self, line):
value = value[1:-1]
value = value.replace('\\\\', '\\').replace('\\"', '"')
pdict[name] = value
return key, pdict
return key, pdict

@property
def method(self):
Expand All @@ -176,7 +176,7 @@ def cookies(self):
try:
cookies = self.headers['cookie']
self._cookies.load(to_bytes(cookies))
except Exception, e:
except Exception:
logging.error('Failed to load cookies')
self.clear_all_cookies()
return self._cookies
Expand All @@ -185,6 +185,11 @@ def cookies(self):
def url(self):
return self.url_parts.geturl()

@property
def host(self):
return urlparse.urlunsplit(
(self.url_parts.scheme, self.url_parts.netloc, '', '', ''))

@staticmethod
def parse_msg(msg):
"""Static method for constructing a Request instance out of a
Expand Down