Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a898f5e
Remove confusing 2 from message
Oct 18, 2019
23da604
Fix error when content type is not provided
Oct 21, 2019
bb2309d
Updated test to properly reflect not sending a content-type
Oct 22, 2019
364be6b
Resource mapper properly encodes special characters in the uri
Oct 23, 2019
508bc86
Use path.sep
Oct 23, 2019
a7db6af
Merge branch 'master' of https://github.com/solid/node-solid-server i…
Nov 4, 2019
6f6f03a
Add failing test for .mp3 extension.
bourgeoa Oct 23, 2019
750edb1
Only add extension if it changes the content type.
RubenVerborgh Oct 23, 2019
30f1216
Resource mapper properly encodes special characters in the uri
Oct 23, 2019
89ba51e
Use path.sep
Oct 23, 2019
030e812
Merge branch 'master' of https://github.com/solid/node-solid-server i…
Nov 4, 2019
ad8de1c
Merge pull request #1336 from solid/fix/1318
jaxoncreed Nov 4, 2019
fbcb949
Merge branch 'dev' of https://github.com/solid/node-solid-server into…
Nov 4, 2019
0a958f2
Merge pull request #1323 from solid/fix/1316
jaxoncreed Nov 4, 2019
e0b3a64
Merge fix/1324 with dev
Nov 4, 2019
68f8fca
Correct _getContentTypeFromExtension name
Nov 4, 2019
1ff9728
Merge pull request #1327 from solid/fix/1324
jaxoncreed Nov 4, 2019
55be05f
Merge branch 'dev' of https://github.com/solid/node-solid-server into…
Nov 4, 2019
8e9820d
Fixed user not logged in 2
jaxoncreed Nov 6, 2019
7e5ef82
Fix tests for new cookie name
Nov 6, 2019
1593a4c
Fixed 1321 allowing for ranked accept mime types when requesting inde…
Nov 6, 2019
ca65cf3
Bump deps: mashlib
Nov 7, 2019
6f0707d
Merge pull request #1343 from megoth/mashlib-fix
jaxoncreed Nov 7, 2019
a2882cf
PUT copy body for contentType application/json
bourgeoa Nov 7, 2019
0dadca0
Merge pull request #1340 from solid/fix/1317
jaxoncreed Nov 8, 2019
18aea70
Merge pull request #1341 from solid/fix/1321
jaxoncreed Nov 8, 2019
4610103
Merge branch 'dev' into master
bourgeoa Nov 11, 2019
9ec1320
Merge pull request #1346 from bourgeoa/master
jaxoncreed Nov 13, 2019
d3a8321
Bump to version 5.2.2
Nov 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ function initAuthentication (app, argv) {
*/
function sessionSettings (secureCookies, host) {
let sessionSettings = {
name: 'nssidp.sid',
secret: uuid.v1(),
saveUninitialized: false,
resave: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function handler (req, res, next) {

let ret
try {
ret = await ldp.get(options, req.accepts('html'))
ret = await ldp.get(options, req.accepts(['html', 'turtle', 'rdf+xml', 'n3', 'ld+json']) === 'html')
} catch (err) {
// use globHandler if magic is detected
if (err.status === 404 && glob.hasMagic(path)) {
Expand Down
11 changes: 5 additions & 6 deletions lib/ldp.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ class LDP {
}
// const { url: putUrl } = await this.resourceMapper.mapFileToUrl({ path: resourceUrl, hostname })

// HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data
// for JSON bodies. So, the stream needs to be reset
if (contentType.includes('application/json')) {
stream = intoStream(JSON.stringify(stream.body))
}

await ldp.put(resourceUrl, stream, contentType)
return URL.parse(originalUrl).path
}
Expand Down Expand Up @@ -240,6 +234,11 @@ class LDP {

// Directory created, now write the file
return withLock(path, { mustExist: false }, () => new Promise((resolve, reject) => {
// HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data
// for JSON bodies. So, the stream needs to be reset
if (contentType.includes('application/json')) {
stream = intoStream(JSON.stringify(stream.body))
}
const file = stream.pipe(fs.createWriteStream(path))
file.on('error', function () {
reject(error(500, 'Error writing data'))
Expand Down
11 changes: 5 additions & 6 deletions lib/requests/sharing-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class SharingRequest extends AuthRequest {
} else {
request.renderForm(null, req, appOrigin)
}
} else {
request.redirectPostSharing()
}
}

Expand Down Expand Up @@ -119,6 +121,8 @@ class SharingRequest extends AuthRequest {

// Redirect once that's all done
request.redirectPostSharing()
} else {
request.redirectPostSharing()
}
}

Expand All @@ -144,12 +148,7 @@ class SharingRequest extends AuthRequest {

isUserLoggedIn () {
// Ensure the user arrived here by logging in
if (!this.session.subject || !this.session.subject._id) {
this.response.status(401)
this.response.send('User not logged in 2')
return false
}
return true
return !!(this.session.subject && this.session.subject._id)
}

getAppUrl () {
Expand Down
33 changes: 25 additions & 8 deletions lib/resource-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { promisify } = require('util')
const { types, extensions } = require('mime-types')
const readdir = promisify(fs.readdir)
const HTTPError = require('./http-error')
const pathUtil = require('path')

/*
* A ResourceMapper maintains the mapping between HTTP URLs and server filenames,
Expand Down Expand Up @@ -33,7 +34,7 @@ class ResourceMapper {
this._defaultContentType = defaultContentType
this._types = { ...types, ...overrideTypes }
this._indexFilename = indexFilename
this._indexContentType = this._getContentTypeByExtension(indexFilename)
this._indexContentType = this._getContentTypeFromExtension(indexFilename)

// If the host needs to be replaced on every call, pre-split the root URL
if (includeHost) {
Expand Down Expand Up @@ -78,8 +79,10 @@ class ResourceMapper {

// Determine the URL by chopping off everything after the dollar sign
const pathname = this._removeDollarExtension(path)
const url = `${this.resolveUrl(hostname)}${encodeURI(pathname)}`
return { url, contentType: this._getContentTypeByExtension(path) }
const url = `${this.resolveUrl(hostname)}${
pathname.split(pathUtil.sep).map((component) => encodeURIComponent(component)).join('/')
}`
return { url, contentType: this._getContentTypeFromExtension(path) }
}

// Maps the request for a given resource and representation format to a server file
Expand All @@ -94,7 +97,7 @@ class ResourceMapper {
let isFolder = filePath.endsWith('/')
let isIndex = searchIndex && filePath.endsWith('/')

// Create the path for a new ressource
// Create the path for a new resource
let path
if (createIfNotExists) {
path = filePath
Expand All @@ -106,8 +109,8 @@ class ResourceMapper {
path += this._indexFilename
}
// If the extension is not correct for the content type, append the correct extension
if (!isFolder && this._getContentTypeByExtension(path) !== contentType) {
path += `$${contentType in extensions ? `.${extensions[contentType][0]}` : '.unknown'}`
if (!isFolder) {
path = this._addContentTypeExtension(path, contentType)
}
// Determine the path of an existing file
} else {
Expand Down Expand Up @@ -136,7 +139,7 @@ class ResourceMapper {
}
}
path = `${folder}${match}`
contentType = this._getContentTypeByExtension(match)
contentType = this._getContentTypeFromExtension(match)
}
return { path, contentType: contentType || this._defaultContentType }
}
Expand All @@ -157,11 +160,25 @@ class ResourceMapper {
}

// Gets the expected content type based on the extension of the path
_getContentTypeByExtension (path) {
_getContentTypeFromExtension (path) {
const extension = /\.([^/.]+)$/.exec(path)
return extension && this._types[extension[1].toLowerCase()] || this._defaultContentType
}

// Appends an extension for the specific content type, if needed
_addContentTypeExtension (path, contentType) {
// If we would guess the wrong content type from the extension, try appending a better one
const contentTypeFromExtension = this._getContentTypeFromExtension(path)
if (contentTypeFromExtension !== contentType) {
// Some extensions fit multiple content types, so only switch if there's an improvement
const newExtension = contentType in extensions ? extensions[contentType][0] : 'unknown'
if (this._types[newExtension] !== contentTypeFromExtension) {
path += `$.${newExtension}`
}
}
return path
}

// Removes possible trailing slashes from a path
_removeTrailingSlash (path) {
return path.replace(/\/+$/, '')
Expand Down
Loading