Skip to content

Commit

Permalink
Merge pull request #104 from solid-contrib/solid-spec-v0.10
Browse files Browse the repository at this point in the history
Allow header
  • Loading branch information
jeff-zucker authored Mar 5, 2024
2 parents ebc8a0f + 17640eb commit f4a7a79
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
12 changes: 8 additions & 4 deletions core/src/handleResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function handleResponse(response, originalRequest) {

headers.link = headers.link || createLinkHeader(item); // LINK

headers.allow = createAllowHeader(this.patch, this.item.mode); // ALLOW
headers.allow = createAllowHeader(item.pathname) // ALLOW

headers['wac-allow'] = createWacHeader(this.item.mode); // WAC-ALLOW

Expand Down Expand Up @@ -211,9 +211,13 @@ function createWacHeader(mode) {
return `user="read write append control",public="read"`;
}

function createAllowHeader(patch, mode) {
// TODO conditions on DELETE (root/ root/.acl can't be deleted)
return 'OPTIONS,HEAD' + (mode.read ? ',GET' : '') + (mode.write ? ',POST,PUT,DELETE' : '') + (mode.write && patch ? ',PATCH' : '');
function createAllowHeader(requestPath) {
// root/ root/.acl can't be deleted
let del = (requestPath === '/' || requestPath === '/.acl') ? '' : ',DELETE'
// no PATCH on Container
if (requestPath.endsWith('/')) return 'OPTIONS,HEAD,GET,POST,PUT' + del
// no POST on Document
else return 'OPTIONS,HEAD,GET,PATCH,PUT' + del
}

function createAcceptHeader(request, headers) {
Expand Down
28 changes: 24 additions & 4 deletions file/tests/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const $rdf = global.$rdf = require('rdflib');
const {SolidRestFile} = require('../');
const libUrl = require('url');

global.$rdf = $rdf;
const client = new SolidRestFile();
const kb = $rdf.graph();
const fetcher = $rdf.fetcher(kb,{fetch:client.fetch.bind(client)});
Expand Down Expand Up @@ -45,6 +46,8 @@ async function getConfig(scheme){
* we assume that test-folder exists and is empty
*/
let base = scheme + "/test-folder4"
let root = host + "/"
let rootAcl = host + "/.acl"
let c1name = "rest/"
let c2name = "deep-folder"
let r1name = "test1.ttl"
Expand Down Expand Up @@ -144,6 +147,8 @@ const resPatchN3_2 = [`@prefix : <#>.
let cfg = {
host : host,
base : base,
root : root,
rootAcl : rootAcl,
dummy : base + "/dummy.txt",
c1name : c1name,
c2name : c2name,
Expand Down Expand Up @@ -184,6 +189,7 @@ async function run(scheme){
let cfg = await getConfig(scheme)
let res, res1
let acceptPatch, acceptPost, acceptPut
let allow

if(scheme==="mem:") cfg.base += "/"
try {res=await PUT(cfg.dummy)}catch(e){console.log(e)}
Expand Down Expand Up @@ -271,12 +277,26 @@ if(check.headers){

// HEAD
res = await HEAD( cfg.deepR )
ok("200 head",res.status==200 && res.headers.get("allow"),res )
ok("200 head",res.status==200,res )

res = await HEAD( cfg.deepR )
ok("200 head Document, no POST in Allow header",res.status==200
&& !res.headers.get("allow").match('POST'), res)

res = await HEAD( cfg.missingFolder )
ok("404 head resource, not found",res.status==404,res )
ok("404 head", res.status === 404,res )

res = await HEAD( cfg.missingFolder )
ok("404 head Container, no PATCH in Allow header", res.status === 404
&& !res.headers.get("allow").match('PATCH'),res )

res = await HEAD( cfg.root )
ok("200 head Container, no DELETE in Allow header", res.status === 200
&& !res.headers.get("allow").match('DELETE'),res )

// console.log(res.headers)
res = await HEAD( cfg.rootAcl )
ok("404 head root/.acl, no DELETE in Allow header", res.status === 404
&& !res.headers.get("allow").match('DELETE'),res )

// GET
res = await GET( cfg.missingFolder )
Expand Down Expand Up @@ -338,7 +358,7 @@ if( check.patch ){
acceptPut = res.headers.get('Accept-Put')
acceptPost = res.headers.get('Accept-Post')
acceptPatch = res.headers.get('Accept-Patch')
ok("200 delete resource",res.status==200
ok("200 delete resource, no accept headers",res.status==200
&& acceptPatch===null && acceptPost=== null && acceptPut=== null,res)

res = await DELETE( cfg.folder1 )
Expand Down

0 comments on commit f4a7a79

Please sign in to comment.