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

HEAD requests are not using the provided request headers #592

Closed
frogleon opened this issue Apr 12, 2024 · 7 comments
Closed

HEAD requests are not using the provided request headers #592

frogleon opened this issue Apr 12, 2024 · 7 comments

Comments

@frogleon
Copy link

Request options passed as part of the initial "HEAD" request to verify if there is a redirect from the original provided URL are not the ones specified in the initial configuration. This could lead to discrepancies across GET and HEAD requests when specific headers are required (even as part of the HEAD request).

@bezoerb
Copy link
Collaborator

bezoerb commented Apr 13, 2024

Hey @frogleon
thanks for submitting this issue. Can you give an example?

@frogleon
Copy link
Author

frogleon commented Apr 16, 2024

Hi @bezoerb , thanks for you answer!

I don't have one, unfortunately. However, let's take for example, this situation:

There is an auth-only URL endpoint that accepts headers as part of the request and grabs the credentials from there; if the auth fails (missing/invalid credentials), there is a 301 redirect to the application's login page.

In this case, the expectation would be that the specified headers are used for the request to succeed.

What is happening is that this HEAD request exists in the code (see: src/file.js:795) and does not use the specified headers before the GET request. The final URL collected would be the login page, not the expected one. Therefore, it will create the wrong critical CSS content.

I hope this helps clarify the issue.

Edit: I'll add the code that I believe is causing this issue:

try {
      const response = await fetch(filepath, {options, request: {method: 'head'}}); // maybe the request field is overwriting entirely the options.request value, not only the "method" field? 
      if (response.url !== url) {
        debug(`(vinylize) found redirect from ${url} to ${response.url}`);
        url = response.url;
      }
    } catch {}

Thank you again!

@gman-wa
Copy link

gman-wa commented Apr 17, 2024

I can second this issue - we set a custom userAgent for got that was only working half the time, and one of my team noticed all the requests with the default got user agent were all HEAD requests. GETs were all using the custom user agent.

@timbednar
Copy link

This is also occurring with Grunt.

@bezoerb
Copy link
Collaborator

bezoerb commented Apr 21, 2024

Hey @frogleon
i just released patch version v7.1.2 which should fix the issue.
Can you please try again?

@gman-wa
Copy link

gman-wa commented Apr 22, 2024

@bezoerb - it's working for me - thanks!

@frogleon
Copy link
Author

Thanks!

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

No branches or pull requests

4 participants