Repository navigation
Convert representations if explicitly requested (not via */*) - #1024
RubenVerborgh wants to merge 4 commits into
Conversation
|
@joachimvh There seems to be a downstream bug now: No idea where the |
e231a65 to
b089765
Compare
It's {
"ContentTypeReplacer:_replacements_key": "text/*",
"ContentTypeReplacer:_replacements_value": "application/octet-stream"
}why did we have this? |
Because it makes sense if a client accepts |
|
What about this case?
This should deliver markdown if the server has a markdown representation available. |
Indeed. |
b089765 to
e2b6a52
Compare
6a4db4c to
a7157c5
Compare
| * if set to `false`, always considers */* a match, so conversion is not needed; | ||
| * if left `undefined`, only considers */* a match if it has the highest preference score | ||
| */ | ||
| public constructor(converter: RepresentationConverter = EMPTY_CONVERTER, ignoreWildcards?: boolean) { |
There was a problem hiding this comment.
Ultimately, I ended up not using the ignoreWildcards in the configuration. (At some point, there was a second IfNeededConverter with ignoreWildcards in one of the later steps.) But let's still leave it in as a choice.
jvherweg
left a comment
There was a problem hiding this comment.
If you do a GET request on a text/turtle document now with accept header text/html,*/*;q=0.8 (doesn't have to be html specifically) you get as output ... application/trig. This is because the IfNeededConverter gets skipped but the ContentTypeReplacer doesn't. I'm guessing this might not be intended?
| headers: { 'content-type': 'text/markdown' }, | ||
| body: markdownBody, | ||
| }); | ||
| assert.equal(res.status, 201); |
There was a problem hiding this comment.
| assert.equal(res.status, 201); | |
| assert.strictEqual(res.status, 201); |
| if (this.ignoreWildcards !== false && wildcardWeight !== 0) { | ||
| // Ignore wildcards if explicitly excluded… | ||
| if (this.ignoreWildcards === true) { | ||
| typePreferences = { ...typePreferences, '*/*': 0 }; | ||
| // …or if the request does not have them as the highest preference | ||
| } else if (wildcardWeight !== 1 && wildcardWeight !== Math.max(...Object.values(typePreferences))) { | ||
| typePreferences = { ...typePreferences, '*/*': 0 }; | ||
| } | ||
| } |
There was a problem hiding this comment.
Not a big fan of having all these kinds of behaviours in this class, but probably not the best way to do it. It mostly confirms that moving everything to the chained converter is going to be the cleanest solution (going to be the next PR that I do).
There was a problem hiding this comment.
Not a big fan of having all these kinds of behaviours in this class
I think it's actually very appropriate here; this is the whole point of IfNeededConverter.
The universal wildcard has a special usage in the Accept header; we shouldn't take it literally as "anything goes" but as "and if needed, I'll take anything else". That's what started #1021, basically.
It mostly confirms that moving everything to the chained converter is going to be the cleanest solution
"Everything" as in "all conversion handlers", sure. But IfNeededConverter allows us to build a nice stack, especially with recent additions. We can basically avoid—at one or multiple places in the conversion chain—to go to a next, more expensive, step when the client is already happy. For instance, Accept: */* does not require any further work, unless for internal types. So we could split all of that up if we wanted to.
There was a problem hiding this comment.
Not a big fan of having all these kinds of behaviours in this class
I think it's actually very appropriate here; this is the whole point of IfNeededConverter.
The universal wildcard has a special usage in the Accept header; we shouldn't take it literally as "anything goes" but as "and if needed, I'll take anything else". That's what started #1021, basically.
It mostly confirms that moving everything to the chained converter is going to be the cleanest solution
"Everything" as in "all conversion handlers", sure. But IfNeededConverter allows us to build a nice stack, especially with recent additions. We can basically avoid—at one or multiple places in the conversion chain—to go to a next, more expensive, step when the client is already happy. For instance, Accept: */* does not require any further work, unless for internal types. So we could split all of that up if we wanted to.
There was a problem hiding this comment.
Note the much simpler definition of "already matches" in #834 (comment); this class gives us a more flexible and reusable definition for other classes as well. Even if we will be adopting the chained converter as default, other configurations might not.
There was a problem hiding this comment.
The ChainedConverter already does path optimization to check if it is theoretically possible to find a path with a better weight than the one it has found so far. So it should quickly see that it can immediately return the resource if it matches the strongest accept header (hopefully). But we can potentially continue the discussion once that PR is there.
a7157c5 to
856b2e9
Compare
Nope; fixed in 856b2e9 |
|
The one issue with this PR is that I would say that this is a major semver change now. Due to the |
I think it's okay. The important cases still work; the ones that do not were broken before. |
One case I'm thinking of is a resource with content-type Btw, is there a reason this is marked as a minor semver change instead of a patch in that case? |
New API feature: |
Can re-add that one. But that would indeed not work for Turtle then (and probably never has). |
|
@RubenVerborgh Shall we close this one then? |
|
Not sure about killing |
Closes #1021
Closes #1023