Commit 51e91fb8 authored by Jiachi Liu's avatar Jiachi Liu

fix decoding

parent 05c44d52
...@@ -5,6 +5,8 @@ import { ...@@ -5,6 +5,8 @@ import {
toNodeOutgoingHttpHeaders, toNodeOutgoingHttpHeaders,
validateURL, validateURL,
encodeHeaderValue, encodeHeaderValue,
decodeHeaderValue,
containsNonAscii,
} from '../utils' } from '../utils'
import { ReflectAdapter } from './adapters/reflect' import { ReflectAdapter } from './adapters/reflect'
...@@ -30,8 +32,13 @@ function handleMiddlewareField( ...@@ -30,8 +32,13 @@ function handleMiddlewareField(
const encodedValue = encodeHeaderValue(value) const encodedValue = encodeHeaderValue(value)
headers.set('x-middleware-request-' + key, encodedValue) headers.set('x-middleware-request-' + key, encodedValue)
keys.push(key) keys.push(key)
// Track headers that were actually encoded (value changed)
if (encodedValue !== value) { // Track headers that contain non-ASCII (either directly or percent-encoded).
// This tells the server which headers need decoding.
// - If value has non-ASCII: we encoded it, needs decoding
// - If value is already encoded and decodes to non-ASCII: needs decoding
const decodedValue = decodeHeaderValue(value)
if (containsNonAscii(value) || containsNonAscii(decodedValue)) {
encodedKeys.push(key) encodedKeys.push(key)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment