Skip to content

Commit 98cb6b3

Browse files
committed
fix: Set the location header when registering a resource
1 parent dc09cf6 commit 98cb6b3

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

documentation/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ in the relevant policies that determine access.
115115
The Solid identifier of the resource is irrelevant,
116116
and not even known by the AS.
117117
If the request is successful,
118-
the AS responds with a 201 status code.
119-
The location header contains the new identifier.
118+
the AS responds with a 201 status code and the UMA identifier in the body.
119+
The location header contains the URL needed to update the registration.
120120
The RS stores this identifier, linked to the Solid identifier, for future use.
121121

122122
### About identifiers

packages/uma/src/routes/ResourceRegistration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createErrorMessage,
55
getLoggerFor,
66
InternalServerError,
7+
joinUrl,
78
KeyValueStorage,
89
MethodNotAllowedHttpError,
910
NotFoundHttpError,
@@ -93,6 +94,7 @@ export class ResourceRegistrationRequestHandler extends HttpHandler {
9394

9495
return ({
9596
status: 201,
97+
headers: { location: `${joinUrl(request.url.href, encodeURIComponent(resource))}` },
9698
body: {
9799
_id: resource,
98100
user_access_policy_uri: 'TODO: implement policy UI',

packages/uma/test/unit/routes/ResourceRegistration.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'jest-rdf';
22
import {
3+
joinUrl,
34
KeyValueStorage,
45
MethodNotAllowedHttpError,
56
NotFoundHttpError,
@@ -96,6 +97,7 @@ describe('ResourceRegistration', (): void => {
9697
it('registers the resource using the name as identifier.', async(): Promise<void> => {
9798
await expect(handler.handle(input)).resolves.toEqual({
9899
status: 201,
100+
headers: { location: `http://example.com/foo/name` },
99101
body: { _id: 'name', user_access_policy_uri: 'TODO: implement policy UI' },
100102
});
101103
expect(resourceStore.set).toHaveBeenCalledTimes(1);
@@ -109,6 +111,7 @@ describe('ResourceRegistration', (): void => {
109111
input.request.body!.resource_defaults = { pred: [ 'scope' ], '@reverse': { 'rPred': [ 'otherScope' ]}};
110112
await expect(handler.handle(input)).resolves.toEqual({
111113
status: 201,
114+
headers: { location: `http://example.com/foo/name` },
112115
body: { _id: 'name', user_access_policy_uri: 'TODO: implement policy UI' },
113116
});
114117
expect(policies.addRule).toHaveBeenCalledTimes(1);
@@ -144,6 +147,7 @@ describe('ResourceRegistration', (): void => {
144147
input.request.body!.name = 'entry';
145148
await expect(handler.handle(input)).resolves.toEqual({
146149
status: 201,
150+
headers: { location: `http://example.com/foo/entry` },
147151
body: { _id: 'entry', user_access_policy_uri: 'TODO: implement policy UI' },
148152
});
149153
expect(policies.addRule).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)