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

Forwarded event fetch request having double headers in Nuxt/SEO module (triggered in server middleware) #956

Closed
Xenossolitarius opened this issue Jan 16, 2025 · 9 comments
Labels
bug Something isn't working

Comments

@Xenossolitarius
Copy link

Environment

node 20
mac m3

Reproduction

Connected all the dots

Describe the bug

On the receiving API
Invalid URL

at new URL (node:internal/url:806:29)
at getRequestURL (/XXX/node_modules/.pnpm/h3@1.13.1/node_modules/h3/dist/index.mjs:337:10)
at Object.handler (server/middleware/01.auth.ts:8:1)
at /XXX/node_modules/.pnpm/h3@1.13.1/node_modules/h3/dist/index.mjs:1963:31
at async Object.callAsync (/XXX/node_modules/.pnpm/unctx@2.4.1/node_modules/unctx/dist/index.mjs:72:16)
at async toNodeHandle (/XXX/node_modules/.pnpm/h3@1.13.1/node_modules/h3/dist/index.mjs:2255:7)
at async ufetch (/XXX/node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/fetch/index.mjs:9:17)
at async $fetchRaw2 (/XXX/node_modules/.pnpm/ofetch@1.4.1/node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:258:26)
at async $fetchRaw2 (/XXX/node_modules/.pnpm/ofetch@1.4.1/node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:311:14)
at async $fetch2 (/XXX/node_modules/.pnpm/ofetch@1.4.1/node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:316:15)

Breaks with

Image

while using event as a fetchContainer

on

getRequestURL

Image

where the vars are:

Image

the double "localhost:3000, localhost:3000" shouldn't be there I guess

Also this error only happens in nuxt server middleware when getRequestURL is called

https://github.com/unjs/h3/pull/946/files

I believe the change above introduced such issue

Not really sure if this is the upstream issue but tnx again for taking a look!

Additional context

Logs

@Xenossolitarius Xenossolitarius added the bug Something isn't working label Jan 16, 2025
@Xenossolitarius Xenossolitarius changed the title Forwarded event fetch request having double headers in Nuxt/SEO module (triggered in server middleware Forwarded event fetch request having double headers in Nuxt/SEO module (triggered in server middleware) Jan 16, 2025
@harlan-zw
Copy link
Contributor

On my end it looks like it's caused by a workaround I did for the bug fixed in: #946

I can remove my workaround but that will break earlier versions so probably better to merge them correctly.

@harlan-zw
Copy link
Contributor

Actually I think this is a bug purely on the Sitemap module using defu to merge the headers now that I'm looking into the h3 source.

Will move discussion to nuxt-modules/sitemap#400

@harlan-zw harlan-zw closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2025
@Xenossolitarius
Copy link
Author

Yea, sorry couldn't debug it properly. Goes too deep into some very internal logic there

@harlan-zw
Copy link
Contributor

I'm not convinced of my above point either now actually, no idea 🤷

Will track in sitemap for now

@Xenossolitarius
Copy link
Author

Ok, i'll try to debug it today and will report the results.

@harlan-zw
Copy link
Contributor

This would likely fix it but I'm concerned it may introduce regressions nuxt-modules/sitemap#402

@Xenossolitarius
Copy link
Author

I ve tracked the headers joined by defu and it's simple:

{
   Accept: "application/json",
   Host: "localhost:3000"
}

So i don't really see an issue here with this. I'll try to track whats happening on the h3 side

@Xenossolitarius
Copy link
Author

Xenossolitarius commented Jan 17, 2025

@harlan-zw OK i think i've found what the issue is

Image

Headers are both capitalized Host and lowercase host

Image

As you can see the new h3 addition getProxyRequestHeaders return the lowercase localhost and yours event fetch init code adds the capitalized Host.

It's a giant side effect of the whole pipeline. Now not sure if sitemap module needs uppercase Host or should the h3 change the logic regarding the joining of headers for the host parameter.

Hope this helps

@Xenossolitarius
Copy link
Author

Fixed downstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants