summaryrefslogtreecommitdiff
path: root/test/data/fetcher.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/data/fetcher.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/data/fetcher.py')
-rwxr-xr-xtest/data/fetcher.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/data/fetcher.py b/test/data/fetcher.py
index 7c9e4ff0..1ea8e337 100755
--- a/test/data/fetcher.py
+++ b/test/data/fetcher.py
@@ -249,6 +249,21 @@ RESOURCES: List[Resource] = [
local_path=(DATA_PATH / "defined_namespaces/rdfs.ttl"),
),
FileResource(
+ remote=Request(
+ "http://www.w3.org/2000/01/rdf-schema#",
+ headers={"Accept": "application/rdf+xml"},
+ ),
+ local_path=(DATA_PATH / "defined_namespaces/rdfs.rdf"),
+ ),
+ FileResource(
+ remote=Request("http://www.w3.org/ns/adms.rdf"),
+ local_path=(DATA_PATH / "defined_namespaces/adms.rdf"),
+ ),
+ FileResource(
+ remote=Request("http://www.w3.org/ns/adms.ttl"),
+ local_path=(DATA_PATH / "defined_namespaces/adms.ttl"),
+ ),
+ FileResource(
remote=Request("https://www.w3.org/ns/rdftest.ttl"),
local_path=(DATA_PATH / "defined_namespaces/rdftest.ttl"),
),