Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 0 additions & 17 deletions lib/capability-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @module capability-discovery
*/
const express = require('express')
const addLink = require('./header').addLink
const util = require('./utils')

const serviceConfigDefaults = {
Expand Down Expand Up @@ -31,26 +30,10 @@ function capabilityDiscovery () {
var router = express.Router('/')

// Advertise the server capability discover endpoint
router.options('*', serviceEndpointHeader)
router.get('/.well-known/solid', serviceCapabilityDocument(serviceConfigDefaults))
return router
}

/**
* Handles advertising the server capability endpoint (adds a Link Relation
* header of type `service`, points to the capability document).
* To be used with OPTIONS requests.
* @method serviceEndpointHeader
* @param req
* @param res
* @param next
*/
function serviceEndpointHeader (req, res, next) {
let serviceEndpoint = `${util.uriBase(req)}/.well-known/solid`
addLink(res, serviceEndpoint, 'service')
next()
}

/**
* Serves the service capability document (containing server root URL, including
* any base path the user specified in config, server API endpoints, etc).
Expand Down
11 changes: 11 additions & 0 deletions lib/handlers/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const addLink = require('../header').addLink
const utils = require('../utils')

module.exports = handler

function handler (req, res, next) {
let serviceEndpoint = `${utils.uriBase(req)}/.well-known/solid`
addLink(res, serviceEndpoint, 'service')
res.header('Accept-Patch', 'application/sparql-update')
next()
}
2 changes: 2 additions & 0 deletions lib/ldp-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var get = require('./handlers/get')
var post = require('./handlers/post')
var put = require('./handlers/put')
var del = require('./handlers/delete')
var options = require('./handlers/options')
var patch = require('./handlers/patch')
var index = require('./handlers/index')
var errorPages = require('./handlers/error-pages')
Expand All @@ -32,6 +33,7 @@ function LdpMiddleware (corsSettings) {
router.patch('/*', acl.allow('Append'), patch)
router.put('/*', acl.allow('Write'), put)
router.delete('/*', acl.allow('Write'), del)
router.options('/*', options)

// Errors
router.use(errorPages)
Expand Down
20 changes: 20 additions & 0 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ describe('HTTP APIs', function () {
.expect(204, done)
})

describe('Accept-Patch header', function () {
it('should be present for resources', function (done) {
server.options('/sampleContainer/example1.ttl')
.expect('Accept-Patch', 'application/sparql-update')
.expect(204, done)
})

it('should be present for containers', function (done) {
server.options('/sampleContainer/')
.expect('Accept-Patch', 'application/sparql-update')
.expect(204, done)
})

it('should be present for non-rdf resources', function (done) {
server.options('/sampleContainer/solid.png')
.expect('Accept-Patch', 'application/sparql-update')
.expect(204, done)
})
})

it('should have an empty response', function (done) {
server.options('/sampleContainer/example1.ttl')
.expect(emptyResponse)
Expand Down