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

[Theme] Fix cart requests #4497

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-eggs-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Fix cart/add request in development.
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,17 @@ describe('dev proxy', () => {
// Removed:
event.node.req.headers.connection = '...'
event.node.req.headers['proxy-authenticate'] = '...'
event.node.req.headers.accept = 'text/html'
event.node.req.headers.host = 'abnb'
// Kept:
event.node.req.headers.accept = 'text/html'
event.node.req.headers.cookie = 'oreo'
event.node.req.headers['user-agent'] = 'vitest'
event.node.req.headers['x-custom'] = 'true'

expect(getProxyStorefrontHeaders(event)).toMatchInlineSnapshot(`
{
"X-Forwarded-For": "42",
"accept": "text/html",
"cookie": "oreo",
"user-agent": "vitest",
"x-custom": "true",
Expand Down
8 changes: 4 additions & 4 deletions packages/theme/src/cli/utilities/theme-environment/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
defineEventHandler,
clearResponseHeaders,
sendProxy,
getProxyRequestHeaders,
getRequestHeaders,
getRequestWebStream,
getRequestIP,
type H3Event,
Expand Down Expand Up @@ -167,7 +167,9 @@ const HOP_BY_HOP_HEADERS = [
'trailer',
'transfer-encoding',
'upgrade',
'expect',
'content-security-policy',
'host',
]

function patchProxiedResponseHeaders(ctx: DevServerContext, event: H3Event, response: Response | NodeResponse) {
Expand Down Expand Up @@ -203,10 +205,8 @@ function patchProxiedResponseHeaders(ctx: DevServerContext, event: H3Event, resp
* Filters headers to forward to SFR.
*/
export function getProxyStorefrontHeaders(event: H3Event) {
const proxyRequestHeaders = getProxyRequestHeaders(event) as {[key: string]: string}
const proxyRequestHeaders = getRequestHeaders(event) as {[key: string]: string}

// H3 already removes most hop-by-hop request headers:
// https://github.com/unjs/h3/blob/ac6d83de2abe5411d4eaea8ecf2165ace16a65f3/src/utils/proxy.ts#L25
for (const headerKey of HOP_BY_HOP_HEADERS) {
delete proxyRequestHeaders[headerKey]
}
Expand Down
Loading