Skip to content

Commit af1c48d

Browse files
committed
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.
1 parent a8094d9 commit af1c48d

17 files changed

+159
-1
lines changed

index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5809,7 +5809,7 @@ <h3>LoadDocumentCallback</h3>
58095809
<ol class="changed">
58105810
<li>Create a new {{Promise}} <var>promise</var> and return it.
58115811
The following steps are then executed asynchronously.</li>
5812-
<li>Set <var>document</var> to the body retrieved from
5812+
<li id="LoadDocumentCallback-step-2">Set <var>document</var> to the body retrieved from
58135813
the resource identified by <a data-link-for="LoadDocumentCallback">url</a>,
58145814
or by otherwise locating a resource associated with <a data-link-for="LoadDocumentCallback">url</a>.
58155815
When requesting remote documents the request MUST prefer <a>Content-Type</a> <code>application/ld+json</code>
@@ -5824,6 +5824,13 @@ <h3>LoadDocumentCallback</h3>
58245824
<li>Set <var>documentUrl</var> to the location of the retrieved resource
58255825
considering redirections (exclusive of HTTP status <code>303</code> "See Other" redirects
58265826
as discussed in [[?cooluris]]).</li>
5827+
<li>If the retrieved resource's <a>Content-Type</a> is not <code>application/ld+json</code>
5828+
nor any media type with a <code>+json</code> suffix as defined in [[RFC6839]],
5829+
and the response has an HTTP Link Header [[RFC8259]] using the <code>alternate</code> link relation
5830+
with type `application/ld+json`,
5831+
set <var>url</var> to the associated <code>href</code> relative to the previous <var>url</var>
5832+
and restart the algorithm from <a href="#LoadDocumentCallback-step-2">step 2</a>,
5833+
ensuring that <var>documentUrl</var> is set to the original <var>url</var>.</li>
58275834
<li>If the retrieved resource's <a>Content-Type</a> is <code>application/json</code>
58285835
or any media type with a <code>+json</code> suffix as defined in [[RFC6839]]
58295836
except <code>application/ld+json</code>,
@@ -6372,6 +6379,9 @@ <h2>Changes since JSON-LD Community Group Final Report</h2>
63726379
a context. When this is set, vocabulary-relative IRIs, such as the
63736380
<a>entries</a> of <a>node objects</a>, are expanded or compacted relative
63746381
to the <a>base IRI</a> and the <a>vocabulary mapping</a> using string concatenation.</li>
6382+
<li>In the <a>LoadDocumentCallback</a>, if the retrieved content is not `application/ld+json`
6383+
and there is a link header with `rel=alternate` and `type=application/ld+json`, redirect
6384+
to that content.</li>
63756385
</ul>
63766386
</section>
63776387

tests/remote-doc-manifest.jsonld

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,56 @@
134134
},
135135
"input": "remote-doc/0013-in.json",
136136
"expect": "remote-doc/0013-out.jsonld"
137+
}, {
138+
"@id": "#tla01",
139+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
140+
"name": "Redirects if type is text/html",
141+
"purpose": "Load an alternate link if type is not ld+json and rel=alternate.",
142+
"option": {
143+
"httpLink": "<la01-alternate.jsonld>; rel=\"alternate\"; type=\"application/ld+json\""
144+
},
145+
"input": "remote-doc/la01-in.html",
146+
"expect": "remote-doc/la01-out.jsonld"
147+
}, {
148+
"@id": "#tla02",
149+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
150+
"name": "Does not redirect if type is application/ld+json",
151+
"purpose": "Load an alternate link if type is not ld+json and rel=alternate.",
152+
"option": {
153+
"httpLink": "<la02-alternate.jsonld>; rel=\"alternate\"; type=\"application/ld+json\""
154+
},
155+
"input": "remote-doc/la02-in.jsonld",
156+
"expect": "remote-doc/la02-out.jsonld"
157+
}, {
158+
"@id": "#tla03",
159+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
160+
"name": "Does not redirect if link type is not application/ld+json",
161+
"purpose": "Load an alternate link if type is not ld+json and rel=alternate.",
162+
"option": {
163+
"httpLink": "<la03-alternate.json>; rel=\"alternate\"; type=\"application/json\""
164+
},
165+
"input": "remote-doc/la03-in.json",
166+
"expect": "remote-doc/la03-out.jsonld"
167+
}, {
168+
"@id": "#tla04",
169+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
170+
"name": "Does not redirect if type is application/json",
171+
"purpose": "Load an alternate link if type is not ld+json and rel=alternate.",
172+
"option": {
173+
"httpLink": "<la04-alternate.jsonld>; rel=\"alternate\"; type=\"application/ld+json\""
174+
},
175+
"input": "remote-doc/la04-in.json",
176+
"expect": "remote-doc/la04-out.jsonld"
177+
}, {
178+
"@id": "#tla05",
179+
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
180+
"name": "Base remains that of original document",
181+
"purpose": "Load an alternate link if type is not ld+json and rel=alternate.",
182+
"option": {
183+
"httpLink": "<la05-alternate.jsonld>; rel=\"alternate\"; type=\"application/ld+json\""
184+
},
185+
"input": "remote-doc/la05-in.html",
186+
"expect": "remote-doc/la05-out.jsonld"
137187
}
138188
]
139189
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example.org/"
4+
},
5+
"content": "alternate"
6+
}

tests/remote-doc/la01-in.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<html>
2+
<head>
3+
<title>Content to be skipped</title>
4+
<script type="application/ld+json">
5+
{
6+
"@context": {
7+
"@vocab": "http://example.org/"
8+
},
9+
"content": "skipped"
10+
}
11+
</script>
12+
</head>
13+
<body>
14+
<p>This content should be skipped</p>
15+
</body>
16+
</html>

tests/remote-doc/la01-out.jsonld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[{
2+
"http://example.org/content": [{"@value": "alternate"}]
3+
}]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example.org/"
4+
},
5+
"content": "alternate"
6+
}

tests/remote-doc/la02-in.jsonld

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example.org/"
4+
},
5+
"content": "not skipped"
6+
}

tests/remote-doc/la02-out.jsonld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[{
2+
"http://example.org/content": [{"@value": "not skipped"}]
3+
}]

tests/remote-doc/la03-alternate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example.org/"
4+
},
5+
"content": "alternate"
6+
}

tests/remote-doc/la03-in.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example.org/"
4+
},
5+
"content": "not skipped"
6+
}

tests/remote-doc/la03-out.jsonld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[{
2+
"http://example.org/content": [{"@value": "not skipped"}]
3+
}]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example.org/"
4+
},
5+
"content": "alternate"
6+
}

tests/remote-doc/la04-in.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example.org/"
4+
},
5+
"content": "not skipped"
6+
}

tests/remote-doc/la04-out.jsonld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[{
2+
"http://example.org/content": [{"@value": "not skipped"}]
3+
}]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"@vocab": "http://example.org/"
4+
},
5+
"@id": "",
6+
"content": "alternate"
7+
}

tests/remote-doc/la05-in.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<html>
2+
<head>
3+
<title>Content to be skipped</title>
4+
<script type="application/ld+json">
5+
{
6+
"@context": {
7+
"@vocab": "http://example.org/"
8+
},
9+
"@id": "",
10+
"content": "skipped"
11+
}
12+
</script>
13+
</head>
14+
<body>
15+
<p>This content should be skipped</p>
16+
</body>
17+
</html>

tests/remote-doc/la05-out.jsonld

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[{
2+
"@id": "https://w3c.github.io/json-ld-api/tests/remote-doc/la05-in.html",
3+
"http://example.org/content": [{"@value": "alternate"}]
4+
}]

0 commit comments

Comments
 (0)