-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Add .Data.Headers in GetRemote #12521
Comments
a few hours of 😴 and a quit lesson 🧑🎓 in building Hugo I would say that the most practical approach would be to add needed Fields only. the Link is returned as unicoded string and to extract only the needed rel types it looks quite simple. <(.*?)>\s*;\s*.*?(rel="(first|last|next|(prev(:?ious)?)|start|self)(\s+(first|last|next|(prev(:?ious)?)|start|self))?").*?(,|$) I could imagine that it would be good to have the unparsed Link stored, too.
the presence of each link type is determined by the query result. So only available links are in the Response. The first page fe. wouldn't provide a previous link in the response header field tested withjust added a Dumped in a Template:
will result in:
|
Just a thought - What about an Opt-In for complex header fields.... {{ $opts := dict
"method" "post"
"body" `{"complete": true}`
"headers" (dict "Content-Type" "application/json")
"responseHeaderFields= (slice "Links", ...)
}} Will limit the performance impact if one has many Get-Remote Calls without need for links. |
Support Link Response fields in GetRemote Result object
Discourse 49894
Issue
Different APIs use different Response-Header fields to return additional data about the Response.
Especially paginating REST APIs (GitHub, GitLab guess there are many) used in combination with GetRemote are affected.
Hugo currently only provides access to the Content-Type filed through it's Data Interface in
resource Object returned from GetRemote
I would like to have see the Link Header fields for Pagination at the resource.
Link Response Header Field (RFC 5988)
RFC has a complete grammar in section 5
Just the key points for the stuff used in pagination here:
relation types are defined in
section 622
commonly used types are
;-)
So we have multiple types in a rel field that may link to the same Url. And two different types
for the same (prev and previous) Hurray.
Example from GitHub
Implementation thoughts
Implementation effort varies on the degree of Link attribute support
1.2 all types
1.3 list of types (minimal: next,prev(ios),first,last,start)
2 complete Link RFC
3 all or some other Headers
I would vote for 1.2 maybe 1.1 so it's full supported. Guess you have some Go libraries already in
use. The grammar for the Link attribute seems to regex capture handlebar.
Easy access
should be dead simple $resource.Links.First $resource.Links "first" ... no puzzling around with
walking a structure or index function.
Should not fail
If the link cannot be parsed completely it should not fail but store it in a String representation
maybe Resource.Header.LinkRaw ...
Field that may be worth adding
languages.
Further considerations
For simplicity all fields exposed are directly available at the .Data field.
Could be moved to a .Data.Header storing the Response headers. Just one field currently for the
Response-Header, so a deprecation now and duplicate/link it to .Data.Headers. or an interface,
getter ... i'm not in Go. The new link Field might be widely used because of paginating APIs
utilized with GetRemote and Content Adapters. imho if there should be a change, early is better ;-)
Dunno if these will be a conflict candidate later but at lest a point to consider
Resources
The text was updated successfully, but these errors were encountered: