protegeproject / protege

Protege Desktop
http://protege.stanford.edu
Other
971 stars 229 forks source link

HTTP Accept header for ontology URLs with and without version #1099

Closed aljoshakoecher closed 1 year ago

aljoshakoecher commented 1 year ago

Hey everyone, I am setting up a W3ID redirect and I want to ensure content negotiation, i.e.

Furthermore, I want to have proper versioning for the ontology so that a specific version may be imported. For all this, I have created the following .htaccess file:

# Redirect ontology with version
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml [OR]
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^css/(\d\.\d\.\d)/?$ https://raw.githubusercontent.com/<repo>/v$1/<file> [R=301,NC]

# Redirect for ontology without version left out..
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml [OR]
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^css/?$ https://raw.githubusercontent.com/<repo>/main/<file> [R=301,NC]

# Redirect HTML requests to the main repository page
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteRule ^css/?$ https://github.com/<repo> [R=301,NC]

What this does is basically: Check the HTTP Accept header. If it is set to application/rdf+xml or text/turtle then serve the ontology file. If the URL contains a version, use that version to get the exact ontology version. If there is no version, return the current file of the main branch. If the HTTP Accept asks for HTML, just redirect to the repository page.

Now to the problem:

Why does Protege set different HTTP Accept headers for these two URLs?

  1. http://www.w3id.org/.../css
  2. http://www.w3id.org/.../css/1.0.0

Is this intentional?

aljoshakoecher commented 1 year ago

After some wasted hours I just stumbled across an issue in the W3id repo that helped me resolve this issue: https://github.com/perma-id/w3id.org/issues/2021

Solution: Protege seems to expect a 303 status code. Imports worked for me as soon as I changed from 301 to 303 for the ontology redirects.