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

The built-in server responds to HEAD requests with 404 #2851

Closed
arnog opened this issue Jan 19, 2023 · 4 comments
Closed

The built-in server responds to HEAD requests with 404 #2851

arnog opened this issue Jan 19, 2023 · 4 comments

Comments

@arnog
Copy link

arnog commented Jan 19, 2023

I don't have a simple test case to share, however, the ServeHTTP() function in pkg/api/serve_other.go file does indeed seem to only handle GET (line 129). Instead it should probably handle HEAD and GET similarly, but avoid doing a rebuild or returning a body for HEAD.

@evanw
Copy link
Owner

evanw commented Jan 19, 2023

I can add support for HEAD. I think it would have to trigger a build though since you can't know whether the path in the URL is valid or not without doing a build.

What are you using HEAD for? It could be good for me to know why you need this in case it's relevant when I'm working on the dev server.

@arnog
Copy link
Author

arnog commented Jan 19, 2023

Yes, I see your point about the rebuild. It probably won't be required in most cases, but I guess it doesn't really hurt.

My use case is as follow: I need to determine the URL of a file located next to the library file (it's some ancillary assets (fonts) that I need to load dynamically). In order to do that I need to resolve the URL of the library file, as in some cases (when using CDNs) the actual URL can be behind some redirects. Using a GET would work, but it's inefficient since I don't need the payload, just the resolved URL. HEAD satisfies this by return the resolved URL, which I can then use as a base to locate the ancillary files.

Those assets have been manually copied into the servedir during a build step prior to invoking esbuild.

@lukeed
Copy link
Contributor

lukeed commented Jan 19, 2023

HEAD is also used purely for "is X still the latest?" requests via etag and/or content-length lookups (oof)

Haven't had a moment to try out 0.17.x yet, but if there's still work being done in this space, it'd be great if serve send down assets with weak W/"file-hash" etag header and then tracked/persisted that for the serve lifetime. Most frontend build systems that rely on ESM for development (vite, svelte kit, astro, etc) are heavily relying on this 304 pattern already. While they're not HEADs, it's related. Plus a number of backend frameworks route all HEAD requests to the GET for that route since they're identical, sans body

@evanw evanw closed this as completed in f48391a Jan 19, 2023
@arnog
Copy link
Author

arnog commented Jan 19, 2023

Excellent! 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

3 participants