Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[WebLink] Add class to parse Link headers from HTTP responses#60420
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
5a7a0d4
to4378fb8
CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the review@OskarStark, I addressed all your comments. |
0783d20
tocb63475
CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nit
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
* | ||
* @author Jérôme Tamarelle <jerome@tamarelle.net> | ||
*/ | ||
final class HttpHeaderParser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
final + no base type = not SOLID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I blindly replicated the same thing asHttpHeaderSerializer
. Let's remove thefinal
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We should remove final there also then.
BTW, did you consider a service definition to allow autowiring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I removed thefinal
from the other class and added framework integration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should we add an interface to provide autowiring based on the interface rather than the concrete implementation ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
In absolute terms, that's what we should do. We would do the same forHttpHeaderSerializer
then.
But I don't see why anyone would write a different implementation.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
$rels = preg_split('/\s+/', trim($params['rel'])); | ||
unset($params['rel']); | ||
$link = new Link(array_shift($rels), $href); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd suggest starting with null instead of array_shift, it should be more performant
d3f3139
to2afdc15
CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
} | ||
} | ||
if (!isset($params['rel'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
what should be done ifrel
is an array because it is specified multiple times ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Good question. I'll take the first value according to the spec:
5.3. Relation Type
The relation type of a link is conveyed in the "rel" parameter's value. The "rel" parameter MUST NOT appear more than once in a given link-value; occurrences after the first MUST be ignored by parsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I wonder if we should still return links that doesn't have arel
attribute. They will never be returned bygetLinksByRel
, but give exhaustivity if the parser is used for tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Updated to return links without rel.
Uh oh!
There was an error while loading.Please reload this page.
c74c0b3
to7df291f
Compare298e56a
intosymfony:7.4Uh oh!
There was an error while loading.Please reload this page.
Some HTTP API expose a Link header for pagination (SeeGitHub API orSentry API), so it's necessary to parse this header to consume the API.
Since we already have a WebLink component, I think it's a good fit to add the logic for parsing the HTTP header into this component.
The existing packages use simplified pattern and does not support all the spec features: