def test_noFragments(self): """ L{client._urljoin} does not include a fragment identifier in the resulting URL if neither the base nor the new path include a fragment identifier. """ self.assertEqual(client._urljoin(b"http://foo.com/bar", b"/quux"), b"http://foo.com/quux") self.assertEqual(client._urljoin(b"http://foo.com/bar#", b"/quux"), b"http://foo.com/quux") self.assertEqual(client._urljoin(b"http://foo.com/bar", b"/quux#"), b"http://foo.com/quux")
def test_preserveFragments(self): """ L{client._urljoin} preserves the fragment identifier from either the new path or the base URL respectively, as specified in the HTTP 1.1 bis draft. @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2} """ self.assertEqual(client._urljoin(b"http://foo.com/bar#frag", b"/quux"), b"http://foo.com/quux#frag") self.assertEqual(client._urljoin(b"http://foo.com/bar", b"/quux#frag2"), b"http://foo.com/quux#frag2") self.assertEqual(client._urljoin(b"http://foo.com/bar#frag", b"/quux#frag2"), b"http://foo.com/quux#frag2")
def test_noFragments(self): """ L{client._urljoin} does not include a fragment identifier in the resulting URL if neither the base nor the new path include a fragment identifier. """ self.assertEqual(client._urljoin(b'http://foo.com/bar', b'/quux'), b'http://foo.com/quux') self.assertEqual(client._urljoin(b'http://foo.com/bar#', b'/quux'), b'http://foo.com/quux') self.assertEqual(client._urljoin(b'http://foo.com/bar', b'/quux#'), b'http://foo.com/quux')
def test_noFragments(self): """ L{client._urljoin} does not include a fragment identifier in the resulting URL if neither the base nor the new path include a fragment identifier. """ self.assertEquals( client._urljoin(b'http://foo.com/bar', b'/quux'), b'http://foo.com/quux') self.assertEquals( client._urljoin(b'http://foo.com/bar#', b'/quux'), b'http://foo.com/quux') self.assertEquals( client._urljoin(b'http://foo.com/bar', b'/quux#'), b'http://foo.com/quux')
def _resolveLocation(self, requestURI, location): from twisted.web.client import _urljoin from urlparse import urlparse, urlsplit old_url = urlsplit(requestURI)[1].split(":") go_to = urlsplit(location)[1].split(":") if self._onRedirect == "sticky": location = location.replace(go_to[0], old_url[0]) elif self._onRedirect == "stickyport": def _preparePort(url): urlsplited = urlsplit(url)[1].split(":") scheme = urlsplit(url).scheme \ if urlsplit(url).scheme else "http" if scheme == "http": url = url.replace(urlsplited[0], urlsplited[0]+":80") elif scheme == "https": url = url.replace(urlsplited[0], urlsplited[0]+":443") return url if len(old_url) != 2: requestURI = _preparePort(requestURI) old_url = urlsplit(requestURI)[1].split(":") if len(go_to) != 2: location = _preparePort(location) go_to = urlsplit(location)[1].split(":") if not self._proxy: location = location.replace(go_to[1], str(self._port)) else: location = location.replace(go_to[1], old_url[1]) location = _urljoin(requestURI, location) log.debug("Locating to URL: %s" % location) return location
def test_preserveFragments(self): """ L{client._urljoin} preserves the fragment identifier from either the new path or the base URL respectively, as specified in the HTTP 1.1 bis draft. @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#section-7.1.2} """ self.assertEqual(client._urljoin(b'http://foo.com/bar#frag', b'/quux'), b'http://foo.com/quux#frag') self.assertEqual( client._urljoin(b'http://foo.com/bar', b'/quux#frag2'), b'http://foo.com/quux#frag2') self.assertEqual( client._urljoin(b'http://foo.com/bar#frag', b'/quux#frag2'), b'http://foo.com/quux#frag2')
def _resolveLocation(self, requestURI, location): from twisted.web.client import _urljoin from urlparse import urlparse, urlsplit old_url = urlsplit(requestURI)[1].split(":") go_to = urlsplit(location)[1].split(":") if self._onRedirect == "sticky": location = location.replace(go_to[0], old_url[0]) elif self._onRedirect == "stickyport": def _preparePort(url): urlsplited = urlsplit(url)[1].split(":") scheme = urlsplit(url).scheme \ if urlsplit(url).scheme else "http" if scheme == "http": url = url.replace(urlsplited[0], urlsplited[0] + ":80") elif scheme == "https": url = url.replace(urlsplited[0], urlsplited[0] + ":443") return url if len(old_url) != 2: requestURI = _preparePort(requestURI) old_url = urlsplit(requestURI)[1].split(":") if len(go_to) != 2: location = _preparePort(location) go_to = urlsplit(location)[1].split(":") if not self._proxy: location = location.replace(go_to[1], str(self._port)) else: location = location.replace(go_to[1], old_url[1]) location = _urljoin(requestURI, location) log.debug("Locating to URL: %s" % location) return location