Skip to content

Commit e126aad

Browse files
Merge branch 'master' into dz_oidc
2 parents 30a57ed + 3ce6e21 commit e126aad

File tree

11 files changed

+49
-26
lines changed

11 files changed

+49
-26
lines changed

lib/capability-discovery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function capabilityDiscovery () {
4747
function serviceCapabilityDocument (serviceConfig) {
4848
return (req, res) => {
4949
// Add the server root url
50-
serviceConfig.root = util.uriBase(req) // TODO make sure we align with the rest
50+
serviceConfig.root = util.getFullUri(req) // TODO make sure we align with the rest
5151
// Add the 'apps' urls section
5252
serviceConfig.apps = req.app.locals.appUrls
5353
res.json(serviceConfig)

lib/handlers/allow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function allow (mode) {
2727
}
2828

2929
// Obtain and store the ACL of the requested resource
30-
const baseUri = utils.uriBase(req)
30+
const baseUri = utils.getBaseUri(req)
3131
req.acl = new ACL(baseUri + reqPath, {
3232
origin: req.get('origin'),
3333
host: req.protocol + '://' + req.get('host'),

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.getBaseUri(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/handlers/get.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function handler (req, res, next) {
2424
var ldp = req.app.locals.ldp
2525
var includeBody = req.method === 'GET'
2626
var negotiator = new Negotiator(req)
27-
var baseUri = utils.uriBase(req)
27+
var baseUri = utils.getFullUri(req)
2828
var path = res.locals.path || req.path
2929
var requestedType = negotiator.mediaType()
3030
var possibleRDFType = negotiator.mediaType(RDFs)
@@ -140,7 +140,7 @@ function globHandler (req, res, next) {
140140
var ldp = req.app.locals.ldp
141141
var root = !ldp.idp ? ldp.root : ldp.root + req.hostname + '/'
142142
var filename = utils.uriToFilename(req.path, root)
143-
var uri = utils.uriBase(req)
143+
var uri = utils.getFullUri(req)
144144
const requestUri = url.resolve(uri, req.path)
145145

146146
var globOptions = {
@@ -158,9 +158,11 @@ function globHandler (req, res, next) {
158158
// Matches found
159159
var globGraph = $rdf.graph()
160160

161+
let reqOrigin = utils.getBaseUri(req)
162+
161163
debugGlob('found matches ' + matches)
162164
async.each(matches, function (match, done) {
163-
var baseUri = utils.filenameToBaseUri(match, uri, root)
165+
var baseUri = utils.filenameToBaseUri(match, reqOrigin, root)
164166
fs.readFile(match, {encoding: 'utf8'}, function (err, fileData) {
165167
if (err) {
166168
debugGlob('error ' + err)

lib/handlers/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function linkAuthProvider (req, res) {
2222
}
2323

2424
function linkServiceEndpoint (req, res) {
25-
let serviceEndpoint = `${utils.uriBase(req)}/.well-known/solid`
25+
let serviceEndpoint = `${utils.getFullUri(req)}/.well-known/solid`
2626
addLink(res, serviceEndpoint, 'service')
2727
}
2828

lib/handlers/patch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function patchHandler (req, res, next) {
2929
const root = !ldp.idp ? ldp.root : `${ldp.root}${req.hostname}/`
3030
const target = {}
3131
target.file = utils.uriToFilename(req.path, root)
32-
target.uri = utils.uriAbs(req) + req.originalUrl
32+
target.uri = utils.getBaseUri(req) + req.originalUrl
3333
target.contentType = mime.lookup(target.file) || DEFAULT_TARGET_TYPE
3434
debug('PATCH -- Target <%s> (%s)', target.uri, target.contentType)
3535

lib/ldp-container.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var ns = require('solid-namespace')($rdf)
1212
var S = require('string')
1313
// var turtleExtension = '.ttl'
1414
var mime = require('mime-types')
15+
const url = require('url')
1516

1617
function addContainerStats (ldp, reqUri, filename, resourceGraph, next) {
1718
ldp.stat(filename, function (err, containerStats) {
@@ -37,8 +38,10 @@ function addFile (ldp, resourceGraph, containerUri, reqUri, uri, container, file
3738
return callback(null)
3839
}
3940

41+
let filePath = url.resolve(container, file)
42+
4043
// Get file stats
41-
ldp.stat(container + file, function (err, stats) {
44+
ldp.stat(filePath, function (err, stats) {
4245
if (err) {
4346
// File does not exist, skip
4447
return callback(null)

lib/ldp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class LDP {
171171
async.each(
172172
files,
173173
function (file, cb) {
174-
let fileUri = reqUri + encodeURIComponent(file)
174+
let fileUri = url.resolve(reqUri, encodeURIComponent(file))
175175
ldpContainer.addFile(ldp, resourceGraph, reqUri, fileUri, uri,
176176
filename, file, cb)
177177
},
@@ -395,7 +395,7 @@ class LDP {
395395
if (err) {
396396
metaFile = ''
397397
}
398-
let absContainerUri = baseUri + reqPath
398+
let absContainerUri = url.resolve(baseUri, reqPath)
399399
ldp.listContainer(filename, absContainerUri, baseUri, metaFile, contentType,
400400
function (err, data) {
401401
if (err) {

lib/utils.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports.uriToFilename = uriToFilename
22
module.exports.uriToRelativeFilename = uriToRelativeFilename
33
module.exports.filenameToBaseUri = filenameToBaseUri
4-
module.exports.uriAbs = uriAbs
4+
module.exports.getBaseUri = getBaseUri
55
module.exports.pathBasename = pathBasename
6-
module.exports.uriBase = uriBase
6+
module.exports.getFullUri = getFullUri
77
module.exports.hasSuffix = hasSuffix
88
module.exports.getResourceLink = getResourceLink
99
module.exports.parse = parse
@@ -20,7 +20,7 @@ var path = require('path')
2020
var S = require('string')
2121
var $rdf = require('rdflib')
2222
var from = require('from2')
23-
var url = require('url')
23+
const url = require('url')
2424

2525
/**
2626
* Returns a fully qualified URL from an Express.js Request object.
@@ -98,12 +98,26 @@ function filenameToBaseUri (filename, uri, base) {
9898
return uri + '/' + uriPath
9999
}
100100

101-
function uriAbs (req) {
101+
function getBaseUri (req) {
102102
return req.protocol + '://' + req.get('host')
103103
}
104104

105-
function uriBase (req) {
106-
return uriAbs(req) + (req.baseUrl || '')
105+
/**
106+
* Composes and returns the fully-qualified URI for the request, to be used
107+
* as a base URI for RDF parsing or serialization. For example, if a request
108+
* is to `Host: example.com`, `GET /files/` using the `https:` protocol,
109+
* then:
110+
*
111+
* ```
112+
* getFullUri(req) // -> 'https://example.com/files/'
113+
* ```
114+
*
115+
* @param req {IncomingMessage}
116+
*
117+
* @return {string}
118+
*/
119+
function getFullUri (req) {
120+
return getBaseUri(req) + url.resolve(req.baseUrl, req.path)
107121
}
108122

109123
function pathBasename (fullpath) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "solid-server",
33
"description": "Solid server on top of the file-system",
4-
"version": "3.5.2",
4+
"version": "3.5.3",
55
"author": {
66
"name": "Tim Berners-Lee",
77
"email": "timbl@w3.org"

0 commit comments

Comments
 (0)