From af1c48d30437c5b15e6faf62244b2f29ccdc6ddc Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Mon, 12 Aug 2019 14:52:30 -0700 Subject: [PATCH 1/4] Add support for the `alternate` link relation with type `application/ld+json` to be used as a redirect if the retrieved document is not JSON. For w3c/json-ld-syntax#204. --- index.html | 12 ++++++- tests/remote-doc-manifest.jsonld | 50 ++++++++++++++++++++++++++ tests/remote-doc/la01-alternate.jsonld | 6 ++++ tests/remote-doc/la01-in.html | 16 +++++++++ tests/remote-doc/la01-out.jsonld | 3 ++ tests/remote-doc/la02-alternate.jsonld | 6 ++++ tests/remote-doc/la02-in.jsonld | 6 ++++ tests/remote-doc/la02-out.jsonld | 3 ++ tests/remote-doc/la03-alternate.json | 6 ++++ tests/remote-doc/la03-in.json | 6 ++++ tests/remote-doc/la03-out.jsonld | 3 ++ tests/remote-doc/la04-alternate.jsonld | 6 ++++ tests/remote-doc/la04-in.json | 6 ++++ tests/remote-doc/la04-out.jsonld | 3 ++ tests/remote-doc/la05-alternate.jsonld | 7 ++++ tests/remote-doc/la05-in.html | 17 +++++++++ tests/remote-doc/la05-out.jsonld | 4 +++ 17 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 tests/remote-doc/la01-alternate.jsonld create mode 100644 tests/remote-doc/la01-in.html create mode 100644 tests/remote-doc/la01-out.jsonld create mode 100644 tests/remote-doc/la02-alternate.jsonld create mode 100644 tests/remote-doc/la02-in.jsonld create mode 100644 tests/remote-doc/la02-out.jsonld create mode 100644 tests/remote-doc/la03-alternate.json create mode 100644 tests/remote-doc/la03-in.json create mode 100644 tests/remote-doc/la03-out.jsonld create mode 100644 tests/remote-doc/la04-alternate.jsonld create mode 100644 tests/remote-doc/la04-in.json create mode 100644 tests/remote-doc/la04-out.jsonld create mode 100644 tests/remote-doc/la05-alternate.jsonld create mode 100644 tests/remote-doc/la05-in.html create mode 100644 tests/remote-doc/la05-out.jsonld diff --git a/index.html b/index.html index 7164c0c5..5a287ad1 100644 --- a/index.html +++ b/index.html @@ -5809,7 +5809,7 @@

LoadDocumentCallback

  1. Create a new {{Promise}} promise and return it. The following steps are then executed asynchronously.
  2. -
  3. Set document to the body retrieved from +
  4. Set document to the body retrieved from the resource identified by url, or by otherwise locating a resource associated with url. When requesting remote documents the request MUST prefer Content-Type application/ld+json @@ -5824,6 +5824,13 @@

    LoadDocumentCallback

  5. Set documentUrl to the location of the retrieved resource considering redirections (exclusive of HTTP status 303 "See Other" redirects as discussed in [[?cooluris]]).
  6. +
  7. If the retrieved resource's Content-Type is not application/ld+json + nor any media type with a +json suffix as defined in [[RFC6839]], + and the response has an HTTP Link Header [[RFC8259]] using the alternate link relation + with type `application/ld+json`, + set url to the associated href relative to the previous url + and restart the algorithm from step 2, + ensuring that documentUrl is set to the original url.
  8. If the retrieved resource's Content-Type is application/json or any media type with a +json suffix as defined in [[RFC6839]] except application/ld+json, @@ -6372,6 +6379,9 @@

    Changes since JSON-LD Community Group Final Report

    a context. When this is set, vocabulary-relative IRIs, such as the entries of node objects, are expanded or compacted relative to the base IRI and the vocabulary mapping using string concatenation.
  9. +
  10. In the LoadDocumentCallback, if the retrieved content is not `application/ld+json` + and there is a link header with `rel=alternate` and `type=application/ld+json`, redirect + to that content.
  11. diff --git a/tests/remote-doc-manifest.jsonld b/tests/remote-doc-manifest.jsonld index d2086514..261f1dd7 100644 --- a/tests/remote-doc-manifest.jsonld +++ b/tests/remote-doc-manifest.jsonld @@ -134,6 +134,56 @@ }, "input": "remote-doc/0013-in.json", "expect": "remote-doc/0013-out.jsonld" + }, { + "@id": "#tla01", + "@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"], + "name": "Redirects if type is text/html", + "purpose": "Load an alternate link if type is not ld+json and rel=alternate.", + "option": { + "httpLink": "; rel=\"alternate\"; type=\"application/ld+json\"" + }, + "input": "remote-doc/la01-in.html", + "expect": "remote-doc/la01-out.jsonld" + }, { + "@id": "#tla02", + "@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"], + "name": "Does not redirect if type is application/ld+json", + "purpose": "Load an alternate link if type is not ld+json and rel=alternate.", + "option": { + "httpLink": "; rel=\"alternate\"; type=\"application/ld+json\"" + }, + "input": "remote-doc/la02-in.jsonld", + "expect": "remote-doc/la02-out.jsonld" + }, { + "@id": "#tla03", + "@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"], + "name": "Does not redirect if link type is not application/ld+json", + "purpose": "Load an alternate link if type is not ld+json and rel=alternate.", + "option": { + "httpLink": "; rel=\"alternate\"; type=\"application/json\"" + }, + "input": "remote-doc/la03-in.json", + "expect": "remote-doc/la03-out.jsonld" + }, { + "@id": "#tla04", + "@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"], + "name": "Does not redirect if type is application/json", + "purpose": "Load an alternate link if type is not ld+json and rel=alternate.", + "option": { + "httpLink": "; rel=\"alternate\"; type=\"application/ld+json\"" + }, + "input": "remote-doc/la04-in.json", + "expect": "remote-doc/la04-out.jsonld" + }, { + "@id": "#tla05", + "@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"], + "name": "Base remains that of original document", + "purpose": "Load an alternate link if type is not ld+json and rel=alternate.", + "option": { + "httpLink": "; rel=\"alternate\"; type=\"application/ld+json\"" + }, + "input": "remote-doc/la05-in.html", + "expect": "remote-doc/la05-out.jsonld" } ] } diff --git a/tests/remote-doc/la01-alternate.jsonld b/tests/remote-doc/la01-alternate.jsonld new file mode 100644 index 00000000..672295e9 --- /dev/null +++ b/tests/remote-doc/la01-alternate.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "@vocab": "http://example.org/" + }, + "content": "alternate" +} \ No newline at end of file diff --git a/tests/remote-doc/la01-in.html b/tests/remote-doc/la01-in.html new file mode 100644 index 00000000..228b26c1 --- /dev/null +++ b/tests/remote-doc/la01-in.html @@ -0,0 +1,16 @@ + + + Content to be skipped + + + +

    This content should be skipped

    + + \ No newline at end of file diff --git a/tests/remote-doc/la01-out.jsonld b/tests/remote-doc/la01-out.jsonld new file mode 100644 index 00000000..a5d1e558 --- /dev/null +++ b/tests/remote-doc/la01-out.jsonld @@ -0,0 +1,3 @@ +[{ + "http://example.org/content": [{"@value": "alternate"}] +}] \ No newline at end of file diff --git a/tests/remote-doc/la02-alternate.jsonld b/tests/remote-doc/la02-alternate.jsonld new file mode 100644 index 00000000..672295e9 --- /dev/null +++ b/tests/remote-doc/la02-alternate.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "@vocab": "http://example.org/" + }, + "content": "alternate" +} \ No newline at end of file diff --git a/tests/remote-doc/la02-in.jsonld b/tests/remote-doc/la02-in.jsonld new file mode 100644 index 00000000..05fcb19a --- /dev/null +++ b/tests/remote-doc/la02-in.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "@vocab": "http://example.org/" + }, + "content": "not skipped" +} \ No newline at end of file diff --git a/tests/remote-doc/la02-out.jsonld b/tests/remote-doc/la02-out.jsonld new file mode 100644 index 00000000..e2c788c0 --- /dev/null +++ b/tests/remote-doc/la02-out.jsonld @@ -0,0 +1,3 @@ +[{ + "http://example.org/content": [{"@value": "not skipped"}] +}] \ No newline at end of file diff --git a/tests/remote-doc/la03-alternate.json b/tests/remote-doc/la03-alternate.json new file mode 100644 index 00000000..672295e9 --- /dev/null +++ b/tests/remote-doc/la03-alternate.json @@ -0,0 +1,6 @@ +{ + "@context": { + "@vocab": "http://example.org/" + }, + "content": "alternate" +} \ No newline at end of file diff --git a/tests/remote-doc/la03-in.json b/tests/remote-doc/la03-in.json new file mode 100644 index 00000000..05fcb19a --- /dev/null +++ b/tests/remote-doc/la03-in.json @@ -0,0 +1,6 @@ +{ + "@context": { + "@vocab": "http://example.org/" + }, + "content": "not skipped" +} \ No newline at end of file diff --git a/tests/remote-doc/la03-out.jsonld b/tests/remote-doc/la03-out.jsonld new file mode 100644 index 00000000..e2c788c0 --- /dev/null +++ b/tests/remote-doc/la03-out.jsonld @@ -0,0 +1,3 @@ +[{ + "http://example.org/content": [{"@value": "not skipped"}] +}] \ No newline at end of file diff --git a/tests/remote-doc/la04-alternate.jsonld b/tests/remote-doc/la04-alternate.jsonld new file mode 100644 index 00000000..672295e9 --- /dev/null +++ b/tests/remote-doc/la04-alternate.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "@vocab": "http://example.org/" + }, + "content": "alternate" +} \ No newline at end of file diff --git a/tests/remote-doc/la04-in.json b/tests/remote-doc/la04-in.json new file mode 100644 index 00000000..05fcb19a --- /dev/null +++ b/tests/remote-doc/la04-in.json @@ -0,0 +1,6 @@ +{ + "@context": { + "@vocab": "http://example.org/" + }, + "content": "not skipped" +} \ No newline at end of file diff --git a/tests/remote-doc/la04-out.jsonld b/tests/remote-doc/la04-out.jsonld new file mode 100644 index 00000000..e2c788c0 --- /dev/null +++ b/tests/remote-doc/la04-out.jsonld @@ -0,0 +1,3 @@ +[{ + "http://example.org/content": [{"@value": "not skipped"}] +}] \ No newline at end of file diff --git a/tests/remote-doc/la05-alternate.jsonld b/tests/remote-doc/la05-alternate.jsonld new file mode 100644 index 00000000..8039161a --- /dev/null +++ b/tests/remote-doc/la05-alternate.jsonld @@ -0,0 +1,7 @@ +{ + "@context": { + "@vocab": "http://example.org/" + }, + "@id": "", + "content": "alternate" +} \ No newline at end of file diff --git a/tests/remote-doc/la05-in.html b/tests/remote-doc/la05-in.html new file mode 100644 index 00000000..4fb2995e --- /dev/null +++ b/tests/remote-doc/la05-in.html @@ -0,0 +1,17 @@ + + + Content to be skipped + + + +

    This content should be skipped

    + + \ No newline at end of file diff --git a/tests/remote-doc/la05-out.jsonld b/tests/remote-doc/la05-out.jsonld new file mode 100644 index 00000000..55700a0e --- /dev/null +++ b/tests/remote-doc/la05-out.jsonld @@ -0,0 +1,4 @@ +[{ + "@id": "https://w3c.github.io/json-ld-api/tests/remote-doc/la05-in.html", + "http://example.org/content": [{"@value": "alternate"}] +}] \ No newline at end of file From eefa60116522cce12157bab4ba7792e4ae10d6fc Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 14 Aug 2019 09:21:36 -0700 Subject: [PATCH 2/4] RFC8259 => RFC8288. --- index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 5a287ad1..39c65ad8 100644 --- a/index.html +++ b/index.html @@ -5826,7 +5826,7 @@

    LoadDocumentCallback

    as discussed in [[?cooluris]]).
  12. If the retrieved resource's Content-Type is not application/ld+json nor any media type with a +json suffix as defined in [[RFC6839]], - and the response has an HTTP Link Header [[RFC8259]] using the alternate link relation + and the response has an HTTP Link Header [[RFC8288]] using the alternate link relation with type `application/ld+json`, set url to the associated href relative to the previous url and restart the algorithm from step 2, @@ -5834,7 +5834,7 @@

    LoadDocumentCallback

  13. If the retrieved resource's Content-Type is application/json or any media type with a +json suffix as defined in [[RFC6839]] except application/ld+json, - and the response has an HTTP Link Header [[RFC8259]] using the http://www.w3.org/ns/json-ld#context link relation, + and the response has an HTTP Link Header [[RFC8288]] using the http://www.w3.org/ns/json-ld#context link relation, set contextUrl to the associated href.

    If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context link relation are found, the promise is rejected with a JsonLdError whose code is set to multiple context link headers @@ -5979,7 +5979,7 @@

    RemoteDocument

    contextUrl
    -
    If available, the value of the HTTP Link Header [[RFC8259]] +
    If available, the value of the HTTP Link Header [[RFC8288]] using the http://www.w3.org/ns/json-ld#context link relation in the response. If the response's Content-Type is application/ld+json, @@ -6197,7 +6197,7 @@

    JsonLdErrorCode

    loading remote context failed
    There was a problem encountered loading a remote context.
    multiple context link headers
    -
    Multiple HTTP Link Headers [[RFC8259]] +
    Multiple HTTP Link Headers [[RFC8288]] using the http://www.w3.org/ns/json-ld#context link relation have been detected.
    processing mode conflict
    From be808f63450f353d4419a2117bd299985ff967cd Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 14 Aug 2019 09:24:18 -0700 Subject: [PATCH 3/4] Alternate link header ignored for all JSON types. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 39c65ad8..9da5762a 100644 --- a/index.html +++ b/index.html @@ -5824,7 +5824,7 @@

    LoadDocumentCallback

  14. Set documentUrl to the location of the retrieved resource considering redirections (exclusive of HTTP status 303 "See Other" redirects as discussed in [[?cooluris]]).
  15. -
  16. If the retrieved resource's Content-Type is not application/ld+json +
  17. If the retrieved resource's Content-Type is not application/json nor any media type with a +json suffix as defined in [[RFC6839]], and the response has an HTTP Link Header [[RFC8288]] using the alternate link relation with type `application/ld+json`, From caecf695735e9f532e3b63f8406dd0c7e94c920d Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 14 Aug 2019 09:25:31 -0700 Subject: [PATCH 4/4] Alternate link header ignored for all JSON types. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 9da5762a..c46ee130 100644 --- a/index.html +++ b/index.html @@ -6379,7 +6379,7 @@

    Changes since JSON-LD Community Group Final Report

    a context. When this is set, vocabulary-relative IRIs, such as the entries of node objects, are expanded or compacted relative to the base IRI and the vocabulary mapping using string concatenation.
  18. -
  19. In the LoadDocumentCallback, if the retrieved content is not `application/ld+json` +
  20. In the LoadDocumentCallback, if the retrieved content is not any JSON media type and there is a link header with `rel=alternate` and `type=application/ld+json`, redirect to that content.