11'use strict'
22
3+ const url = require ( 'url' )
34const HttpError = require ( 'standard-http-error' )
45
56const OPERATIONS = {
@@ -36,9 +37,9 @@ class LdpOperation {
3637 this . bodyStream = options . bodyStream
3738 }
3839
39- static async from ( { req} ) {
40+ static async from ( { req, host } ) {
4041 const { method, headers, session : { authentication } } = req
41- const target = LdpOperation . parseTargetUrl ( req )
42+ const target = LdpOperation . parseTargetUrl ( { req, host } )
4243 const bodyStream = req
4344
4445 const Operation = OPERATIONS [ method ]
@@ -48,19 +49,48 @@ class LdpOperation {
4849
4950 return Operation . from ( { headers, target, bodyStream, authentication} )
5051 }
52+
53+ /**
54+ * Taken from utils.getBaseUri()
55+ *
56+ * @param req {IncomingRequest}
57+ * @param host {SolidHost}
58+ *
59+ * @returns {URL }
60+ */
61+ static parseTargetUrl ( { req, host} ) {
62+ const protocol = host . serverUri . replace ( / : .* / , '' )
63+
64+ return url . format ( {
65+ protocol : protocol || req . protocol ,
66+ host : req . get ( 'host' ) ,
67+ pathname : url . resolve ( req . baseUrl , req . path ) ,
68+ query : req . query
69+ } )
70+ }
71+
72+ writeCommonHeaders ( { res} ) {
73+ // set headers in common to all LDP responses
74+ }
5175}
5276
5377/**
5478 * Checks to see if target exists
5579 */
56- class LdpHeadOperation extends LdpOperation { }
80+ class LdpHeadOperation extends LdpOperation {
81+ writeHeaders ( { res, result, permissions} ) {
82+ this . writeCommonHeaders ( { res} )
83+ // write HEAD-specific headers
84+ }
85+ }
5786
5887/**
5988 * Use cases to handle:
60- * - LdpListContainerRequest , if target is an ldp container
89+ * - "List Container" request , if target is an ldp container
6190 * - However, if Accept: header is HTML, check if index.html exists
6291 * - Need to also support similar use case if index.ttl exists
63- * - Otherwise, plain LdpGetRequest
92+ * - "Glob pattern request" if glob magic chars are detected (ie `*`)
93+ * - Otherwise, plain Get request
6494 */
6595class LdpGetOperation extends LdpOperation { }
6696
0 commit comments