Python cookielib.request_host() Examples
The following are 9
code examples of cookielib.request_host().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cookielib
, or try the search function
.
Example #1
Source File: test_cookielib.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_request_host(self): from urllib2 import Request from cookielib import request_host # this request is illegal (RFC2616, 14.2.3) req = Request("http://1.1.1.1/", headers={"Host": "www.acme.com:80"}) # libwww-perl wants this response, but that seems wrong (RFC 2616, # section 5.2, point 1., and RFC 2965 section 1, paragraph 3) #self.assertEqual(request_host(req), "www.acme.com") self.assertEqual(request_host(req), "1.1.1.1") req = Request("http://www.acme.com/", headers={"Host": "irrelevant.com"}) self.assertEqual(request_host(req), "www.acme.com") # not actually sure this one is valid Request object, so maybe should # remove test for no host in url in request_host function? req = Request("/resource.html", headers={"Host": "www.acme.com"}) self.assertEqual(request_host(req), "www.acme.com") # port shouldn't be in request-host req = Request("http://www.acme.com:2345/resource.html", headers={"Host": "www.acme.com:5432"}) self.assertEqual(request_host(req), "www.acme.com")
Example #2
Source File: test_cookielib.py From BinderFilter with MIT License | 6 votes |
def test_request_host(self): from urllib2 import Request from cookielib import request_host # this request is illegal (RFC2616, 14.2.3) req = Request("http://1.1.1.1/", headers={"Host": "www.acme.com:80"}) # libwww-perl wants this response, but that seems wrong (RFC 2616, # section 5.2, point 1., and RFC 2965 section 1, paragraph 3) #self.assertEqual(request_host(req), "www.acme.com") self.assertEqual(request_host(req), "1.1.1.1") req = Request("http://www.acme.com/", headers={"Host": "irrelevant.com"}) self.assertEqual(request_host(req), "www.acme.com") # not actually sure this one is valid Request object, so maybe should # remove test for no host in url in request_host function? req = Request("/resource.html", headers={"Host": "www.acme.com"}) self.assertEqual(request_host(req), "www.acme.com") # port shouldn't be in request-host req = Request("http://www.acme.com:2345/resource.html", headers={"Host": "www.acme.com:5432"}) self.assertEqual(request_host(req), "www.acme.com")
Example #3
Source File: test_cookielib.py From oss-ftp with MIT License | 6 votes |
def test_request_host(self): from urllib2 import Request from cookielib import request_host # this request is illegal (RFC2616, 14.2.3) req = Request("http://1.1.1.1/", headers={"Host": "www.acme.com:80"}) # libwww-perl wants this response, but that seems wrong (RFC 2616, # section 5.2, point 1., and RFC 2965 section 1, paragraph 3) #self.assertEqual(request_host(req), "www.acme.com") self.assertEqual(request_host(req), "1.1.1.1") req = Request("http://www.acme.com/", headers={"Host": "irrelevant.com"}) self.assertEqual(request_host(req), "www.acme.com") # not actually sure this one is valid Request object, so maybe should # remove test for no host in url in request_host function? req = Request("/resource.html", headers={"Host": "www.acme.com"}) self.assertEqual(request_host(req), "www.acme.com") # port shouldn't be in request-host req = Request("http://www.acme.com:2345/resource.html", headers={"Host": "www.acme.com:5432"}) self.assertEqual(request_host(req), "www.acme.com")
Example #4
Source File: test_cookielib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_request_host(self): from urllib2 import Request from cookielib import request_host # this request is illegal (RFC2616, 14.2.3) req = Request("http://1.1.1.1/", headers={"Host": "www.acme.com:80"}) # libwww-perl wants this response, but that seems wrong (RFC 2616, # section 5.2, point 1., and RFC 2965 section 1, paragraph 3) #self.assertEqual(request_host(req), "www.acme.com") self.assertEqual(request_host(req), "1.1.1.1") req = Request("http://www.acme.com/", headers={"Host": "irrelevant.com"}) self.assertEqual(request_host(req), "www.acme.com") # not actually sure this one is valid Request object, so maybe should # remove test for no host in url in request_host function? req = Request("/resource.html", headers={"Host": "www.acme.com"}) self.assertEqual(request_host(req), "www.acme.com") # port shouldn't be in request-host req = Request("http://www.acme.com:2345/resource.html", headers={"Host": "www.acme.com:5432"}) self.assertEqual(request_host(req), "www.acme.com")
Example #5
Source File: test_cookielib.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_request_host(self): from urllib2 import Request from cookielib import request_host # this request is illegal (RFC2616, 14.2.3) req = Request("http://1.1.1.1/", headers={"Host": "www.acme.com:80"}) # libwww-perl wants this response, but that seems wrong (RFC 2616, # section 5.2, point 1., and RFC 2965 section 1, paragraph 3) #self.assertEquals(request_host(req), "www.acme.com") self.assertEquals(request_host(req), "1.1.1.1") req = Request("http://www.acme.com/", headers={"Host": "irrelevant.com"}) self.assertEquals(request_host(req), "www.acme.com") # not actually sure this one is valid Request object, so maybe should # remove test for no host in url in request_host function? req = Request("/resource.html", headers={"Host": "www.acme.com"}) self.assertEquals(request_host(req), "www.acme.com") # port shouldn't be in request-host req = Request("http://www.acme.com:2345/resource.html", headers={"Host": "www.acme.com:5432"}) self.assertEquals(request_host(req), "www.acme.com")
Example #6
Source File: test_cookielib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_request_host(self): from urllib2 import Request from cookielib import request_host # this request is illegal (RFC2616, 14.2.3) req = Request("http://1.1.1.1/", headers={"Host": "www.acme.com:80"}) # libwww-perl wants this response, but that seems wrong (RFC 2616, # section 5.2, point 1., and RFC 2965 section 1, paragraph 3) #self.assertEqual(request_host(req), "www.acme.com") self.assertEqual(request_host(req), "1.1.1.1") req = Request("http://www.acme.com/", headers={"Host": "irrelevant.com"}) self.assertEqual(request_host(req), "www.acme.com") # not actually sure this one is valid Request object, so maybe should # remove test for no host in url in request_host function? req = Request("/resource.html", headers={"Host": "www.acme.com"}) self.assertEqual(request_host(req), "www.acme.com") # port shouldn't be in request-host req = Request("http://www.acme.com:2345/resource.html", headers={"Host": "www.acme.com:5432"}) self.assertEqual(request_host(req), "www.acme.com")
Example #7
Source File: test_cookielib.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_request_host(self): from urllib2 import Request from cookielib import request_host # this request is illegal (RFC2616, 14.2.3) req = Request("http://1.1.1.1/", headers={"Host": "www.acme.com:80"}) # libwww-perl wants this response, but that seems wrong (RFC 2616, # section 5.2, point 1., and RFC 2965 section 1, paragraph 3) #self.assertEqual(request_host(req), "www.acme.com") self.assertEqual(request_host(req), "1.1.1.1") req = Request("http://www.acme.com/", headers={"Host": "irrelevant.com"}) self.assertEqual(request_host(req), "www.acme.com") # not actually sure this one is valid Request object, so maybe should # remove test for no host in url in request_host function? req = Request("/resource.html", headers={"Host": "www.acme.com"}) self.assertEqual(request_host(req), "www.acme.com") # port shouldn't be in request-host req = Request("http://www.acme.com:2345/resource.html", headers={"Host": "www.acme.com:5432"}) self.assertEqual(request_host(req), "www.acme.com")
Example #8
Source File: webclient.py From vlcp with Apache License 2.0 | 5 votes |
def get_origin_req_host(self): if self.origin_req_host is None: return request_host(self.host) else: return self.origin_req_host
Example #9
Source File: webclient.py From vlcp with Apache License 2.0 | 4 votes |
def __init__(self, url, data = None, method = None, headers = {}, origin_req_host = None, unverifiable = False, rawurl = False): ''' :param url: request url :param data: request data, can be a str/bytes, or a stream(vlcp.event.stream.XXXStream) :param method: request method (GET, POST, ...) :param headers: request header dict ({'user-agent':'myagent'}) :param origin_req_host: origin request host for cookie policy check :param unverifiable: unverifiable for cookie policy check ''' self.url = _str(url, 'ascii') s = urlsplit(self.url, 'http') self.type = 'https' if s.scheme == 'https' else 'http' self.host = s.netloc if not self.host: raise ValueError('Invalid URL: ' + self.url) if rawurl: self.path = urlunsplit(('', '', s.path, s.query, '')) else: self.path = urlunsplit(('', '', quote(s.path), quote(s.query,'/&='), '')) if not self.path: self.path = '/' self.data = data if method is None: if self.data is None: self.method = 'GET' else: self.method = 'POST' else: self.method = method.upper() if self.data is not None: if isinstance(self.data, unicode): self.data = _bytes(self.data) headers = dict(headers) self.headers = dict((_str(k), _str(v, 'iso-8859-1')) for k,v in headers.items()) self.headerdict = dict((k.lower(), v) for k,v in self.headers.items()) self.headermap = dict((k.lower(), k) for k in self.headers.keys()) self.undirectedheaders = {} self.undirectedheaderdict = {} self.undirectedheadermap = {} self.hostname = request_host(self) if origin_req_host is None: origin_req_host = request_host(self) self.origin_req_host = origin_req_host self.unverifiable = unverifiable self.redirect_count = 0 if self.data and not self.has_header('Content-Type'): self.add_header('Content-Type', 'application/x-www-form-urlencoded')