Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept-Patch Accept-Post Accept-Put headers #1754

Merged
merged 6 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions lib/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ async function handler (req, res, next) {
const requestedType = negotiator.mediaType()
const possibleRDFType = negotiator.mediaType(RDFs)

// deprecated kept for compatibility
res.header('MS-Author-Via', 'SPARQL')

res.header('Accept-Patch', 'text/n3, application/sparql-update, application/sparql-update-single-match')
res.header('Accept-Post', '*/*')

// Set live updates
if (ldp.live) {
res.header('Updates-Via', ldp.resourceMapper.resolveUrl(req.hostname).replace(/^http/, 'ws'))
Expand Down
3 changes: 1 addition & 2 deletions lib/handlers/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function contentForNew (contentType) {
// Handles a PATCH request
async function patchHandler (req, res, next) {
debug(`PATCH -- ${req.originalUrl}`)
res.header('MS-Author-Via', 'SPARQL')
try {
// Obtain details of the target resource
const ldp = req.app.locals.ldp
Expand Down Expand Up @@ -70,7 +69,7 @@ async function patchHandler (req, res, next) {
if (!parsePatch) {
throw error(415, `Unsupported patch content type: ${patch.contentType}`)
}

res.header('Accept-Patch', patch.contentType) // is this needed ?
// Parse the patch document and verify permissions
const patchObject = await parsePatch(url, patch.uri, patch.text)
await checkPermission(req, patchObject, resourceExists)
Expand Down
22 changes: 21 additions & 1 deletion test/integration/header-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Header handler', () => {
request = supertest(server)
})

describe('MS-Author-Via', () => {
describe('MS-Author-Via', () => { // deprecated
describeHeaderTest('read/append for the public', {
resource: '/public-ra',
headers: {
Expand All @@ -30,6 +30,26 @@ describe('Header handler', () => {
})
})

describe('Accept-Patch', () => {
describeHeaderTest('read/append for the public', {
resource: '/public-ra',
headers: {
'Accept-Patch': 'text/n3, application/sparql-update, application/sparql-update-single-match',
'Access-Control-Expose-Headers': /(^|,\s*)Accept-Patch(,|$)/
}
})
})

describe('Accept-Post', () => {
describeHeaderTest('read/append for the public', {
resource: '/public-ra',
headers: {
'Accept-Post': '*/*',
'Access-Control-Expose-Headers': /(^|,\s*)Accept-Post(,|$)/
}
})
})

describe('WAC-Allow', () => {
describeHeaderTest('read/append for the public', {
resource: '/public-ra',
Expand Down
2 changes: 1 addition & 1 deletion test/integration/patch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const serverOptions = {
forceUser: `${serverUri}/profile/card#me`
}

describe('PATCH', () => {
describe('PATCH through text/n3', () => {
let request
let server

Expand Down
Loading