Skip to content

Commit

Permalink
fix links header
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-zucker committed Jun 23, 2021
1 parent 7c008bd commit fe55ee7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solid-rest/core",
"version": "2.0.6",
"version": "2.0.7",
"author": "Jeff Zucker",
"license": "MIT",
"description": "treat any storage as a mini Solid server",
Expand Down
48 changes: 27 additions & 21 deletions core/src/handleResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,26 @@ export async function handleResponse(response, originalRequest) {
const request = this.requestObj;
const item = this.item;
const pathname = this.item.pathname;
const fn = this.basename(pathname, item.pathHandler); // CONTENT-TYPE
// const fn = this.basename(pathname, item.pathHandler);
const fn = this.basename(pathname);

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

headers.link = headers.link || createLinkHeader(this.item); // ALLOW
headers.link = headers.link || createLinkHeader(this.item,fn); // LINK

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

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

headers.date = headers.date || new Date(Date.now()).toISOString(); // X-POWERED-BY
headers.date = headers.date || new Date(Date.now()).toISOString(); // DATE

headers['x-powered-by'] = headers['x-powered-by'] || (await this.perform('STORAGE_NAME')); // LOCATION (we pre-populated this in performRequestedMethod.js)
headers['x-powered-by'] = headers['x-powered-by'] || (await this.perform('STORAGE_NAME')); // LOCATION (we pre-populated this in performRequestedMethod.js) // X-POWERED-BY

if (this.response && this.response.headers) headers.location = this.response.headers.location; // ACCEPT-PATCH & MS-AUTHOR-VIA
if (this.response && this.response.headers) headers.location = this.response.headers.location;

if (this.patch) {
if (this.patch) { // ACCEPT-PATCH & MS-AUTHOR-VIA
headers['accept-patch'] = ['application/sparql-update'];
headers['ms-author-via'] = ["SPARQL"];
headers['ms-author-via'] = ["SPARQL"];
}

const body = finalResponse.body || this.response.body || ""; // Now we merge headers we created with response headers, prefering response
Expand All @@ -79,6 +80,9 @@ export async function handleResponse(response, originalRequest) {
headers.status = headers.status || this.response.headers.status || 500;
headers.statusText = headers.statusText || statusText[headers.status];
// Now we create & return the Response object
for(var h of Object.keys(headers)){
if(! headers[h]) delete headers[h];
}

if (originalRequest.plainResponse) {
// from a server that wants to munge
Expand Down Expand Up @@ -119,19 +123,21 @@ function createAllowHeader(patch, mode) {
}

function createLinkHeader(item) {
let fn = item.pathname.replace(/.*\//,'');
let ext = item.extension;
let isContainer = item.isContainer;
let link;
if (ext === '.acl') // .acl not controlledBy or describedBy anything
return `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;else if (ext === '.meta') {
return;
`<${fn}.acl>; rel="acl",` // .meta controlledBy .meta.acl
+ `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;
} else if (isContainer) {
return;
`<.meta>; rel="describedBy", <.acl>; rel="acl",` + `<http://www.w3.org/ns/ldp#Container>; rel="type",` + `<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"` + `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;
} else {
return;
`<${fn}.meta>; rel="describedBy", <${fn}.acl>; rel="acl",` + `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;
return `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;
else if (ext === '.meta') {
return `<${fn}.acl>; rel="acl",` // .meta controlledBy .meta.acl
+ `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;
}
else if (isContainer) {
return `<.meta>; rel="describedBy", <.acl>; rel="acl",` + `<http://www.w3.org/ns/ldp#Container>; rel="type",` + `<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"` + `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;
}
else {
let link = `<${fn}.meta>; rel="describedBy", <${fn}.acl>; rel="acl",` + `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;
console.log(33,item,link);
return link;
}
} // THE END!
8 changes: 4 additions & 4 deletions file/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions file/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solid-rest/file",
"version": "2.0.7",
"version": "2.0.8",
"author": "Jeff Zucker",
"license": "MIT",
"description": "solid-rest plugin for filesystems",
Expand Down Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/solid/solid-rest#readme",
"dependencies": {
"@solid-rest/core": "^2.0.6",
"@solid-rest/core": "^2.0.7",
"concat-stream": "^2.0.0",
"fs-extra": "^9.0.1",
"mime-types": "^2.1.27",
Expand Down
3 changes: 2 additions & 1 deletion file/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import libPath from "path";
import { Readable } from "stream";
import SolidRest from "@solid-rest/core";
//import SolidRest from "@solid-rest/core";
import SolidRest from "../../../core/";
import fs from "fs-extra";
import mime from "mime-types"; // import concatStream from "concat-stream";

Expand Down

0 comments on commit fe55ee7

Please sign in to comment.