summaryrefslogtreecommitdiff
path: root/test/test_misc/test_input_source.py
diff options
context:
space:
mode:
authorIwan Aucamp <aucampia@gmail.com>2023-05-17 18:51:55 +0200
committerGitHub <noreply@github.com>2023-05-17 18:51:55 +0200
commite0b3152a799e7bb04770fcddf010b22c0b05379e (patch)
treebffb71170674bde9f9af2f70e51c490a6808132c /test/test_misc/test_input_source.py
parent2c8d1e13b812a28078b0b31f58386057f54bedb4 (diff)
downloadrdflib-e0b3152a799e7bb04770fcddf010b22c0b05379e.tar.gz
fix: HTTP 308 Permanent Redirect status code handling (#2389)
Change the handling of HTTP status code 308 to behave more like `urllib.request.HTTPRedirectHandler`, most critically, the new 308 handling will create a new `urllib.request.Request` object with the new URL, which will prevent state from being carried over from the original request. One case where this is important is when the domain name changes, for example, when the original URL is `http://www.w3.org/ns/adms.ttl` and the redirect URL is `https://uri.semic.eu/w3c/ns/adms.ttl`. With the previous behaviour, the redirect would contain a `Host` header with the value `www.w3.org` instead of `uri.semic.eu` because the `Host` header is placed in `Request.unredirected_hdrs` and takes precedence over the `Host` header in `Request.headers`. Other changes: - Only handle HTTP status code 308 on Python versions before 3.11 as Python 3.11 will handle 308 by default [[ref](https://docs.python.org/3.11/whatsnew/changelog.html#id128)]. - Move code which uses `http://www.w3.org/ns/adms.ttl` and `http://www.w3.org/ns/adms.rdf` out of `test_guess_format_for_parse` into a separate parameterized test, which instead uses the embedded http server. This allows the test to fully control the `Content-Type` header in the response instead of relying on the value that the server is sending. This is needed because the server is sending `Content-Type: text/plain` for the `adms.ttl` file, which is not a valid RDF format, and the test is expecting `Content-Type: text/turtle`. Fixes: - <https://github.com/RDFLib/rdflib/issues/2382>.
Diffstat (limited to 'test/test_misc/test_input_source.py')
-rw-r--r--test/test_misc/test_input_source.py17
1 files changed, 1 insertions, 16 deletions
diff --git a/test/test_misc/test_input_source.py b/test/test_misc/test_input_source.py
index f3da062b..90e6e238 100644
--- a/test/test_misc/test_input_source.py
+++ b/test/test_misc/test_input_source.py
@@ -11,6 +11,7 @@ from dataclasses import dataclass
# from itertools import product
from pathlib import Path
from test.utils import GraphHelper
+from test.utils.exceptions import ExceptionChecker
from test.utils.httpfileserver import (
HTTPFileInfo,
HTTPFileServer,
@@ -27,7 +28,6 @@ from typing import ( # Callable,
Generic,
Iterable,
Optional,
- Pattern,
TextIO,
Tuple,
Type,
@@ -251,21 +251,6 @@ def call_create_input_source(
yield input_source
-@dataclass
-class ExceptionChecker:
- type: Type[Exception]
- pattern: Optional[Pattern[str]] = None
-
- def check(self, exception: Exception) -> None:
- try:
- assert isinstance(exception, self.type)
- if self.pattern is not None:
- assert self.pattern.match(f"{exception}")
- except Exception:
- logging.error("problem checking exception", exc_info=exception)
- raise
-
-
AnyT = TypeVar("AnyT")