Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Allow HTTP headers to be defined for a preload request #157

Open
IgorMinar opened this issue Apr 1, 2021 · 6 comments
Open

Allow HTTP headers to be defined for a preload request #157

IgorMinar opened this issue Apr 1, 2021 · 6 comments

Comments

@IgorMinar
Copy link

The preload hints don't currently work if a SPA client makes an HTTP request via fetch or XHR apis to the server and in this request it specifies e.g. an Accept header in order to negotiate the format of the response.

A typical symptom of this issue is a warning about the preload request mismatch due to incompatible headers:

Screen Shot 2021-04-01 at 2 25 00 PM

The root cause analysis in angular/angular#34899 (comment) revealed that the issue is indeed setting the Accept header.

Using the Accept header for content negotiation is a relatively common thing in the REST api design: https://restfulapi.net/content-negotiation/ as it allows a server to support multiple response formats using the same URL space.

It would be great if it was possible to specify the Accept header (and potentially other headers as well?) when configuring the preload hint to enable prefetching requests from servers that do use the Accept header for content negotiation.

@yoavweiss
Copy link
Contributor

/cc @annevk
Is this something that came up in other contexts?

@annevk
Copy link
Member

annevk commented Apr 12, 2021

Ideally this follows from the destination (i.e., the as attribute), no? That's also roughly what the specification says today.

@yoavweiss
Copy link
Contributor

@annevk - The destination determines the default Accept headers, but doesn't enable you to add custom ones. In this case, the OP wants to add custom accept to indicate a preference for JSON over XML, resulting in the request not being preloadable.

@annevk
Copy link
Member

annevk commented May 3, 2021

I see. I recall some prior discussion about trying to figure out how to put RequestInit into markup, but I cannot find it.

@cmmartin
Copy link

cmmartin commented Dec 9, 2021

Maybe the type attribute could dictate the Accept header? So if you passed <link type="application/json", you'd get a "accept": "application/json", header instead of the current "accept": "*/*",.

It's not a complete solution, but the accept header seems to be the source of most issues. I can't prefetch anything, because I'll get XML if I don't provide a custom accept header

@yoavweiss yoavweiss changed the title Allow HTTP headers to be defined for the preload request Allow HTTP headers to be defined for a preload request May 4, 2022
@yoavweiss
Copy link
Contributor

Discussion continues at whatwg/html#7887

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

No branches or pull requests

4 participants