File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
packages/core/src/http-adapter Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,17 @@ export const getAdapter = () =>
6666 onBeforeRequest ( ) ;
6767
6868 if ( payload ) {
69- options . headers [ "Content-Length" ] = Buffer . byteLength ( JSON . stringify ( payload ) ) ;
69+ // Calculate Content-Length based on the exact bytes that will be sent.
70+ // If payload is already a string or Buffer (as produced by getAdapterPayload),
71+ // avoid double-stringifying which would lead to incorrect Content-Length.
72+ const payloadAsAny = payload as unknown ;
73+ const isString = typeof payloadAsAny === "string" ;
74+ const isBuffer = Buffer . isBuffer ( payloadAsAny ) ;
75+ const contentLength =
76+ isString || isBuffer
77+ ? Buffer . byteLength ( payloadAsAny as string | Buffer )
78+ : Buffer . byteLength ( JSON . stringify ( payloadAsAny ) ) ;
79+ options . headers [ "Content-Length" ] = contentLength ;
7080 }
7181
7282 const queryString = queryParams ? stringifyQueryParams ( queryParams ) : "" ;
You can’t perform that action at this time.
0 commit comments