Skip to content

Commit

Permalink
Merge pull request #98 from solid-contrib/solid-spec-v0.10
Browse files Browse the repository at this point in the history
Solid spec v0.10
  • Loading branch information
jeff-zucker authored Mar 1, 2024
2 parents 0ff4cc7 + 7775b5a commit e4d3942
Show file tree
Hide file tree
Showing 5 changed files with 4,418 additions and 2,658 deletions.
12 changes: 6 additions & 6 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
},
"homepage": "https://github.com/jeff-zucker/solid-rest#readme",
"dependencies": {
"cross-fetch": "^3.1.5",
"uuid": "8.3.1"
"cross-fetch": "^4.0.0",
"uuid": "9.0.1"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.14.6",
"@babel/plugin-transform-modules-commonjs": "^7.12.1",
"@babel/plugin-transform-modules-umd": "^7.16.0",
"@babel/cli": "^7.23.9",
"@babel/core": "^7.23.9",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/plugin-transform-modules-umd": "^7.23.3",
"babel-preset-es2015": "6.24.1",
"babel-preset-stage-0": "6.24.1"
}
Expand Down
37 changes: 32 additions & 5 deletions core/src/handleResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function handleResponse(response, originalRequest) {
// constructed ones later

if(method.match(/(PUT)/) && finalResponse.headers.status == 200){
finalResponse.headers.status = 201
finalResponse.headers.status = 201
}
if(method.match(/(DELETE|GET|HEAD)/) && finalResponse.headers.status == 201){
finalResponse.headers.status = 200
Expand All @@ -69,7 +69,11 @@ export async function handleResponse(response, originalRequest) {
const pathname = item.pathname;

// const fn = libPath.basename(pathname);
const fn = pathname.replace(/.*\//,'');
const fn = pathname.replace(/.*\//,'');

headers['vary'] = 'accept,authorization,origin'

headers['access-control-expose-headers'] = 'accept-patch,accept-post,accept-put,allow,content-range,etag,last-modified,link,location,updates-via,wac-allow,www-authenticate'

headers['content-type'] = this.item.contentType; // CONTENT-TYPE

Expand Down Expand Up @@ -99,10 +103,10 @@ export async function handleResponse(response, originalRequest) {
if(!headers.url.endsWith('/')) headers.url=headers.url+"/";
*/
}
if (this.patch) { // ACCEPT-PATCH & MS-AUTHOR-VIA
headers['accept-patch'] = ['application/sparql-update'];
/* if (this.patch) { // ACCEPT-PATCH & MS-AUTHOR-VIA
headers['accept-patch'] = ['text/n3', 'application/sparql-update'];
headers['ms-author-via'] = ["SPARQL"];
}
} */


let body = finalResponse.body || this.response.body || ""; // Now we merge headers we created with response headers, prefering response
Expand Down Expand Up @@ -140,9 +144,14 @@ export async function handleResponse(response, originalRequest) {
*/
headers.statusText = headers.statusText || statusText[headers.status];

headers = createAcceptHeader(request, headers) // ACCEPT

headers.etag = `W/"${uuid()}"`;
headers['content-length'] = (typeof Buffer !='undefined') ?Buffer.byteLength(body,'utf8') :(typeof Blob!="undefined") ?(new Blob([body])).size :77;

// TODO (?) last-modified
// TODO Link storage at root : '<http://www.w3.org/ns/pim/space#Storage>; rel="type"'

// Now we create & return the Response object
for(var h of Object.keys(headers)){
if(! headers[h]) delete headers[h];
Expand Down Expand Up @@ -203,9 +212,27 @@ function createWacHeader(mode) {
}

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 createAcceptHeader(request, headers) {
const status = headers.status
// no Accept header
if (request.method.match(/DELETE/) || status >= 500 || status.toString().match(/401|403/)) return headers
// Accept headers on container
if (request.url.endsWith('/')) {
if (status === 404) headers['accept-put'] = ['*/*'];
headers['accept-post'] = ['*/*'];
} else {
// Accept headers on document
headers['accept-put'] = ['*/*'];
headers['accept-patch'] = ['text/n3', 'application/sparql-update'];
headers['ms-author-via'] = ["SPARQL"];
}
return headers
}

function createLinkHeader(item) {
let isContainer = item.isContainer;
let fn = item.pathname.replace(/\/$/,'');
Expand Down
Loading

0 comments on commit e4d3942

Please sign in to comment.