How to use the blacksheep.URL function in blacksheep

To help you get started, we’ve selected a few blacksheep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobertoPrevato / BlackSheep / tests / client / test_cookiejar.py View on Github external
    [URL(b'https://foo.bezkitu.org'), b'foo.org']
])
def test_cookiejar_invalid_domain(request_url, cookie_domain):
    jar = CookieJar()
    cookie = Cookie(b'Name', b'Value', domain=cookie_domain)

    with pytest.raises(InvalidCookieDomain):
        jar.add(request_url, cookie)
github RobertoPrevato / BlackSheep / tests / client / test_cookiejar.py View on Github external
def test_get_cookies_for_url():
    jar = CookieJar()

    jar.add(URL(b'https://foo.org'), Cookie(b'hello', b'world'))

    cookies = list(jar.get_cookies_for_url(URL(b'https://foo.org/hello-world')))

    assert len(cookies) == 1
    assert cookies[0].name == b'hello'
    assert cookies[0].value == b'world'
github RobertoPrevato / BlackSheep / blacksheep / client / session.py View on Github external
def _get_url_without_params(self, url) -> bytes:
        if isinstance(url, str):
            url = url.encode()

        if not isinstance(url, URL):
            url = URL(url)

        if url.is_absolute:
            return url.value

        if self.base_url:
            return self.base_url.join(url).value
        return url.value
github RobertoPrevato / BlackSheep / blacksheep / client / session.py View on Github external
def extract_redirect_location(response: Response) -> URL:
        # if the server returned more than one value, use the first header in order
        location = response.get_first_header(b'Location')
        if not location:
            raise MissingLocationForRedirect(response)
        
        # if the location cannot be parsed as URL, let exception happen: this might be a redirect to a URN!!
        # simply don't follows the redirect, and returns the response to the caller
        try:
            return URL(location)
        except InvalidURL:
            raise UnsupportedRedirect()
github RobertoPrevato / BlackSheep / blacksheep / client / session.py View on Github external
def _get_url_without_params(self, url) -> bytes:
        if isinstance(url, str):
            url = url.encode()

        if not isinstance(url, URL):
            url = URL(url)

        if url.is_absolute:
            return url.value

        if self.base_url:
            return self.base_url.join(url).value
        return url.value
github RobertoPrevato / BlackSheep / blacksheep / client / session.py View on Github external
def _validate_request_url(self, request: Request):
        if not request.url.is_absolute:
            if self.base_url:
                request.url = URL(self._get_url_without_params(request.url))
            else:
                raise ValueError('request.url must be a complete, absolute URL. Either provide a base_url '
                                 'for the client, or specify a full URL for the request.')