Skip to content

Commit f62e23d

Browse files
Fix utils.uriBase() and usage
1 parent 507866e commit f62e23d

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/handlers/allow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function allow (mode) {
1616
if (!ldp.webid) {
1717
return next()
1818
}
19-
var baseUri = utils.uriBase(req)
19+
var baseUri = utils.uriAbs(req)
2020

2121
var acl = new ACL({
2222
debug: debug,

lib/handlers/copy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function handler (req, res, next) {
2020
return next(error(400, 'Source header required'))
2121
}
2222
const fromExternal = !!url.parse(copyFrom).hostname
23-
const serverRoot = utils.uriBase(req)
23+
const serverRoot = utils.uriAbs(req)
2424
const copyFromUrl = fromExternal ? copyFrom : serverRoot + copyFrom
2525
const copyTo = res.locals.path || req.path
2626
const copyToPath = utils.reqToPath(req)
@@ -33,6 +33,6 @@ function handler (req, res, next) {
3333
}
3434
res.set('Location', copyTo)
3535
res.sendStatus(201)
36-
return next()
36+
next()
3737
})
3838
}

lib/utils.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var path = require('path')
1919
var S = require('string')
2020
var $rdf = require('rdflib')
2121
var from = require('from2')
22+
const url = require('url')
2223

2324
function debrack (s) {
2425
if (s.length < 2) {
@@ -65,8 +66,22 @@ function uriAbs (req) {
6566
return req.protocol + '://' + req.get('host')
6667
}
6768

69+
/**
70+
* Composes and returns the fully-qualified URI for the request, to be used
71+
* as a base URI for RDF parsing or serialization. For example, if a request
72+
* is to `Host: example.com`, `GET /files/` using the `https:` protocol,
73+
* then:
74+
*
75+
* ```
76+
* uriBase(req) // -> 'https://example.com/files/'
77+
* ```
78+
*
79+
* @param req {IncomingMessage}
80+
*
81+
* @return {string}
82+
*/
6883
function uriBase (req) {
69-
return uriAbs(req) + (req.baseUrl || '')
84+
return uriAbs(req) + url.resolve(req.baseUrl, req.path)
7085
}
7186

7287
function pathBasename (fullpath) {

0 commit comments

Comments
 (0)