Skip to content

Commit 0c5dc4b

Browse files
Add LdpRequest constructor() with docstring
1 parent a4362fe commit 0c5dc4b

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

lib/api/ldp/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class LdpApi {
5656
async middleware (req, res, next) {
5757
try {
5858
// parse target, operation, (optionally) body, preferences, store authn
59-
const request = await LdpRequest.from({req, host: this.host})
59+
const request = LdpRequest.from({req, host: this.host})
6060

6161
// check that operation is permitted (throws error if not)
6262
const permissions = await this.acl.allow(request)

lib/api/ldp/ldp-request.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@
33
const HttpError = require('standard-http-error')
44

55
class LdpRequest {
6+
/**
7+
* @param options {object}
8+
*
9+
* @param options.host {SolidHost} Host / config object
10+
*
11+
* @param options.target {URL} Parsed full request url
12+
*
13+
* @param options.req {HttpRequest} Save the Express req object, useful
14+
* to access headers/preferences, writeStream for body, etc.
15+
*
16+
* @param [options.authn=null] {object} Authentication object, contains WebID
17+
* string, as well as any bearer credentials/tokens. Needed for
18+
* authenticated fetch (of remote group ACLs, of Copy resources, etc).
19+
* Null if request is not authenticated.
20+
*
21+
* @param [options.parsedBody] {?} Request body, parsed when appropriate
22+
* (when content-type is parse-able)
23+
*/
24+
constructor (options) {
25+
this.host = options.host
26+
this.target = options.target
27+
this.req = options.req
28+
this.authn = options.authn
29+
this.parsedBody = options.parsedBody
30+
}
31+
632
static from ({req, host}) {
733
let request
834

@@ -74,7 +100,8 @@ class LdpRequest {
74100
* Deletes resource or container
75101
*
76102
* Throws:
77-
* - 404 error if resource does not exist
103+
* - 404 error if resource or container does not exist
104+
* - 409 Conflict error if deleting a non-empty container
78105
*/
79106
request = LdpDeleteRequest.from({req, host})
80107
break
@@ -95,7 +122,8 @@ class LdpRequest {
95122
* private resources.
96123
*
97124
* Throws:
98-
* - 400 Source header required error if Source: header is missing
125+
* - 400 'Source header required' error if Source: header is missing
126+
* - 404 if source resource is not found
99127
*/
100128
request = LdpCopyRequest.from({req, host})
101129
break

0 commit comments

Comments
 (0)