Exemplo n.º 1
0
def temporary_redirect(
    request: Request,
    start_response: StartResponse,
    url_part: str,
    *,
    extra_headers: Sequence[Header] = [],
) -> Iterable[bytes]:
    url = absolute_url(request, url_part)
    html = temporary_redirect_page(url)
    all_headers = [_location_header(request, url_part)] + list(extra_headers)
    return respond_with_html(
        start_response,
        html,
        status=HTTPStatus.TEMPORARY_REDIRECT,
        extra_headers=all_headers,
    )
Exemplo n.º 2
0
def see_other(
    request: Request,
    start_response: StartResponse,
    url_part: str,
    *,
    extra_headers: Sequence[Header] = [],
) -> Iterable[bytes]:
    url = absolute_url(request, url_part)
    html = see_other_page(url)
    all_headers = [_location_header(request, url_part)] + list(extra_headers)
    return respond_with_html(
        start_response,
        html,
        status=HTTPStatus.SEE_OTHER,
        extra_headers=all_headers,
    )
Exemplo n.º 3
0
def created_at(
    request: Request,
    start_response: StartResponse,
    url_part: str,
    *,
    extra_headers: Sequence[Header] = [],
) -> Iterable[bytes]:
    """Prepare a 201 Created WSGI response with a Location header.

    The default content-type is "text/html" and the return value generates
    a simple HTML body.
    """

    url = absolute_url(request, url_part)
    html = created_at_page(url)
    all_headers = [_location_header(request, url_part)] + list(extra_headers)
    return respond_with_html(
        start_response,
        html,
        status=HTTPStatus.CREATED,
        extra_headers=all_headers,
    )
Exemplo n.º 4
0
def _location_header(request: Request, url: str) -> Header:
    return "Location", absolute_url(request, url)
Exemplo n.º 5
0
 def do_not_encode_special_characters(self) -> None:
     request = self._create_request()
     url = absolute_url(request, "/foo?bar=baz&abc=%6A;+,@:$")
     assert_equal("https://example.com/foo?bar=baz&abc=%6A;+,@:$", url)
Exemplo n.º 6
0
 def path_is_relative__base_without_slash(self) -> None:
     request = self._create_request(path_info="/path")
     url = absolute_url(request, "foo")
     assert_equal("https://example.com/base/foo", url)
Exemplo n.º 7
0
 def path_is_root_relative(self) -> None:
     request = self._create_request()
     url = absolute_url(request, "/foo")
     assert_equal("https://example.com/foo", url)
Exemplo n.º 8
0
 def path_is_absolute(self) -> None:
     request = self._create_request()
     url = absolute_url(request, "https://example.org/foo")
     assert_equal("https://example.org/foo", url)
Exemplo n.º 9
0
 def path_is_not_ascii(self) -> None:
     request = self._create_request()
     url = absolute_url(request, "/~föo")
     assert_equal("https://example.com/~f%C3%B6o", url)