From a2bd6cc424387022e59f80d5b8029606d019f0ae Mon Sep 17 00:00:00 2001 From: Anatoly Scherbakov Date: Mon, 4 May 2026 22:57:28 +0400 Subject: [PATCH 1/3] Use redirected URL for HTTP extension detection --- yaml_ld/document_loaders/http.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/yaml_ld/document_loaders/http.py b/yaml_ld/document_loaders/http.py index 4219ead..1447690 100644 --- a/yaml_ld/document_loaders/http.py +++ b/yaml_ld/document_loaders/http.py @@ -211,7 +211,6 @@ def __call__( # noqa: WPS210 ) -> RemoteDocument: """Load documents from HTTP sources.""" string_source = str(source) - url = URL(string_source) response = self.session.get( string_source, @@ -236,8 +235,10 @@ def __call__( # noqa: WPS210 raw_content_type, ).mime_type + response_url = URL(string_source) mime_type_by_extension = ( - (extension := url.suffix) and content_types.by_extension(extension) + (extension := response_url.suffix) + and content_types.by_extension(extension) ) mime_type_by_content = None if ' Date: Mon, 4 May 2026 22:57:38 +0400 Subject: [PATCH 2/3] Add redirected Turtle loader regression --- tests/test_http_redirected_turtle_loader.py | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/test_http_redirected_turtle_loader.py diff --git a/tests/test_http_redirected_turtle_loader.py b/tests/test_http_redirected_turtle_loader.py new file mode 100644 index 0000000..1dd1216 --- /dev/null +++ b/tests/test_http_redirected_turtle_loader.py @@ -0,0 +1,50 @@ +from requests import Response, Session +from yarl import URL + +from yaml_ld.document_loaders import default + + +PURL_SOURCE = "http://purl.org/linked-data/cube#" +TURTLE_CONTENT_TYPE = "text/turtle" +TURTLE_URL = "https://raw.githubusercontent.com/example/cube.ttl" +TURTLE_DOCUMENT = b""" +@prefix rdfs: . +@prefix qb: . + +qb:Observation rdfs:label "Observation" . +""" + + +class FakeSession(Session): + def __init__(self, response: Response): + super().__init__() + self.response = response + + def get(self, *args, **kwargs): # noqa: WPS110 + return self.response + + +def _plain_text_turtle_response() -> Response: + response = Response() + response.status_code = 200 + response.url = TURTLE_URL + response.headers["Content-Type"] = "text/plain; charset=utf-8" + response._content = TURTLE_DOCUMENT + return response + + +def test_uses_redirected_url_extension_for_turtle(): + remote_document = default.HTTPDocumentLoader( + session=FakeSession(response=_plain_text_turtle_response()), + )( + source=URL(PURL_SOURCE), + options={ + "base": PURL_SOURCE, + "extractAllScripts": False, + "headers": {}, + }, + ) + + assert remote_document["contentType"] == TURTLE_CONTENT_TYPE + assert remote_document["documentUrl"] == TURTLE_URL + assert remote_document["document"] From 6dc13db3f8a88ecca54379b1239c3f7e560b3375 Mon Sep 17 00:00:00 2001 From: Anatoly Scherbakov Date: Mon, 4 May 2026 22:57:49 +0400 Subject: [PATCH 3/3] Bump package version to 1.1.21 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c4a5c5e..d4fdbee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "yaml-ld" -version = "1.1.20" +version = "1.1.21" description = "YAML-LD for Python" authors = ["Anatoly Scherbakov "] license = "MIT"