linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
562 stars 142 forks source link

Use accept headers that are supplied instead of always overwriting #566

Closed ludwigschub closed 2 years ago

ludwigschub commented 2 years ago

I got aware of this because of the new changes made to ess (enterprise solid server). Because i tried fetching the new webId form of https://id.inrupt.com/ but it would not load the data (only html) even if I passed accept headers to .load(). These changes would allow supplied accept headers to actually work.

ludwigschub commented 2 years ago

I needed to make the condition more elaborate because:

const headers = new Headers({ accept: "text/turtle" })
!!headers.get("accept") // true
!!headers["accept"] // false
jeff-zucker commented 2 years ago

I can not reproduce your problem. This correctly prints out both the ESS and NSS webids as retrieved from the WebID Profile Documents with rdflib.load

const $rdf = require('rdflib');                                                                              
const store = $rdf.graph();                                                                                  
const fetcher = $rdf.fetcher(store);                                                                         

const isa = $rdf.sym("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");                                     
const agent = $rdf.sym("http://xmlns.com/foaf/0.1/Agent");                                                   
const person = $rdf.sym("http://schema.org/Person");                                                         
const ess = $rdf.sym('https://id.inrupt.com/jeff-zucker');                                                   
const nss = $rdf.sym('https://jeff-zucker.solidcommunity.net/profile/card#me');                              

(async ()=>{                                                                                                 
  await fetcher.load(nss,{headers:{Accept:'text/turtle'}})                                                   
  console.log( store.any( null, isa, person, nss.doc() ).value);                                                        
  await fetcher.load(ess,{headers:{Accept:'text/turtle'}})                                                   
  console.log( store.any( null, isa, agent, ess.doc() ).value);                                                         
})(); 
jeff-zucker commented 2 years ago

Apparently, rdflib is able to handle this and correctly supplies RDF from the RDFa source. NSS uses rdflib to send turtle in get requests with accept headers, so a curl or wget with accept headers returns turtle from RDFa. BUT a wget or curl against a ESS WebID will return HTML even with the accept header. This is because the ESS WebID document is not on a Solid server - it is kept separate from the storage server by design. Still, it should supply RDF for the WebID document.

ludwigschub commented 2 years ago

Hey jeff, Thank you for responding so quickly, I really appreciate that! I will try to reproduce the issue i had earlier

ludwigschub commented 2 years ago

I just tested it you are right it works already as it should. My problem is that I am using rdflib@2.2.12 because of incompatibility issues with webpack polyfills that i need to make shex-methods work in the browser. Dependency hell but not the fault of rdflib. In this older version it doesn't work, so i think i have to find another way of using shex so that i can use the latest rdflib version. Sorry for being so quick with creating an issue but it wasn't so easy spotting the origin of the misbehavior :v: