Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically generate Allow and Accept-Patch/Put/Post headers #1241

Merged
merged 3 commits into from
Mar 29, 2022

Conversation

joachimvh
Copy link
Member

📁 Related issues

Closes #577, #572

✍️ Description

Minor issues still remaining:

  • If an error gets thrown the identifier of the target resource does not reach the metadata writer so we can't make conclusions based on that (matters for Allow: POST). Would require a small change in some interfaces to also pass that along should there be a need for that in the future.
  • In case of errors we also don't know if the target resource exists with similar issues as above. We should be covering all cases from the spec correctly though.
  • In case of a SPARQL endpoint, the Accept-Put and Accept-Post headers will still say */* even though we only accept RDF there. Could be fixed by setting the values of those in the config that defines the DataAccessor that is used, but this might complicate it a bit for people wanting to create configs for new data accessors, or that want to disable those headers for some reason so I left it on */* for everything for now. But is fixable if really needed.

This PR also introduces a change to how error classes are generated to make sure they all have the same static functions which makes it easier to add new static functions or new error classes. We could do export const NotFoundHttpError = generateHttpErrorClass(404, 'NotFoundHttpError');, but that way Components.js is unable to deduce the constructor parameters, so each class still has to define its constructor to get around that.

@RubenVerborgh RubenVerborgh self-assigned this Mar 25, 2022
Copy link
Member

@RubenVerborgh RubenVerborgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work!

I think that AllowAcceptMetadataWriter makes several assumptions about how the other classes work. I would leave a TODO to simplify that; I think we should collect more metadata going forward (see below).

The only thing that put my off is RedirectHttpError being treated as a special case; why can't we have consistent instanceof behavior?

If an error gets thrown the identifier of the target resource does not reach the metadata writer so we can't make

I wonder if the target resource should be part of the Error constructor. While it makes sense (it's always an Error for a certain resource), it probably is not feasible.

In case of errors we also don't know if the target resource exists with similar issues as above.

Maybe in general we should be storing much more in metadata of what we "learn" during processing.

.componentsignore Outdated Show resolved Hide resolved
config/file.json Outdated Show resolved Hide resolved
src/http/output/metadata/AllowAcceptMetadataWriter.ts Outdated Show resolved Hide resolved
src/http/output/metadata/AllowAcceptMetadataWriter.ts Outdated Show resolved Hide resolved
src/http/output/metadata/AllowAcceptMetadataWriter.ts Outdated Show resolved Hide resolved
src/http/output/metadata/AllowAcceptMetadataWriter.ts Outdated Show resolved Hide resolved
object: NamedNode | BlankNode | Literal | string | null = null,
graph: MetadataGraph | null = null,
): boolean {
return this.store.countQuads(this.id, predicate, object, graph) > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's make an N3.js issue for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N3.js has a has function actually because it implements the DatasetCore interface. But that one requires an exact triple without wildcards.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's based on the interface defined here: https://rdf.js.org/dataset-spec/#datasetcore-interface . Quad is defined as being a NamedNode/BlankNode/Variable/Quad http://rdf.js.org/data-model-spec/#quad-interface. So only way to have wildcards there would be to use Variables I guess?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could give secret nulls, but yeah 😅
I'm currently working on that PR to have that functionality (fine for now).

Copy link
Member

@RubenVerborgh RubenVerborgh Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N3.js v1.16.0 has has.

src/server/ParsingHttpHandler.ts Show resolved Hide resolved
src/util/Vocabularies.ts Outdated Show resolved Hide resolved
src/util/errors/RedirectHttpError.ts Outdated Show resolved Hide resolved
@joachimvh
Copy link
Member Author

I think we should collect more metadata going forward (see below).

Forgot to mention this in my main comment, but one issue I had after this is that error metadata is in this weird zone where we now have a details object but also an RDF representation. I feel like we should unify this somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants