Skip to content
Open
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
24 changes: 24 additions & 0 deletions src/targets/http/http1.1/client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { HTTPSnippet, Request } from '../../../httpsnippet';

const unicodeRequest = {
method: 'POST',
url: 'http://mockbin.com/har',
headers: [
{
name: 'content-type',
value: 'text/plain',
},
],
postData: {
mimeType: 'text/plain',
text: 'äöü',
},
} as Request;

describe('http:http1.1', () => {
it('should set Content-Length to the byte length of a non-ascii body', () => {
const result = String(new HTTPSnippet(unicodeRequest).convert('http', 'http1.1'));

expect(result).toContain('Content-Length: 6');
});
});
2 changes: 1 addition & 1 deletion src/targets/http/http1.1/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const http11: Client<Http11Options> = {
// RFC 7230 Section 3.3.3. Message Body Length
// Automatically set Content-Length header if option is on, postData is present and no header already exists.
if (opts.autoContentLength && postData.text && !headerKeys.includes('content-length')) {
const length = Buffer.byteLength(postData.text, 'ascii').toString();
const length = Buffer.byteLength(postData.text, 'utf8').toString();
push(`Content-Length: ${length}`);
}

Expand Down