Skip to content
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
173 changes: 44 additions & 129 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions impit-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
"packageManager": "yarn@4.12.0",
"description": "Impit for JavaScript",
"optionalDependencies": {
"impit-darwin-x64": "0.10.1",
"impit-darwin-arm64": "0.10.1",
"impit-win32-x64-msvc": "0.10.1",
"impit-win32-arm64-msvc": "0.10.1",
"impit-darwin-x64": "0.10.1",
"impit-linux-arm64-gnu": "0.10.1",
"impit-linux-arm64-musl": "0.10.1",
"impit-linux-x64-gnu": "0.10.1",
"impit-linux-x64-musl": "0.10.1",
"impit-linux-arm64-gnu": "0.10.1",
"impit-linux-arm64-musl": "0.10.1"
"impit-win32-arm64-msvc": "0.10.1",
"impit-win32-x64-msvc": "0.10.1"
}
}
}
16 changes: 15 additions & 1 deletion impit-node/test/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,27 @@ describe.each([
t.expect(text).toContain('Herman Melville');
});

test('.text() method works with decoding', async (t) => {
test('.text() decodes using Content-Type header charset param', async (t) => {
const response = await impit.fetch(new URL(routes.charset.path, "http://127.0.0.1:3001").href);
const text: string = await response.text();

t.expect(text).toContain(routes.charset.bodyString);
});

test('.text() decodes using <meta charset> prescan', async (t) => {
const response = await impit.fetch(new URL(routes.charsetMetaCharset.path, "http://127.0.0.1:3001").href);
const text: string = await response.text();

t.expect(text).toContain(routes.charsetMetaCharset.bodyString);
});

test('.text() decodes using <meta http-equiv> prescan', async (t) => {
const response = await impit.fetch(new URL(routes.charsetMetaHttpEquiv.path, "http://127.0.0.1:3001").href);
const text: string = await response.text();

t.expect(text).toContain(routes.charsetMetaHttpEquiv.bodyString);
});

test('.json() method works', async (t) => {
const response = await impit.fetch(getHttpBinUrl('/json'));
const json = await response.json();
Expand Down
36 changes: 34 additions & 2 deletions impit-node/test/mock.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ import express from 'express';
import { Server } from 'http';
import { Server as ProxyServer } from 'proxy-chain';

// "Příliš žluťoučký kůň úpěl ďábelské ódy" encoded in Windows-1250
const WIN1250_BODY = Buffer.from([0x50, 0xf8, 0xed, 0x6c, 0x69, 0x9a, 0x20, 0x9e, 0x6c, 0x75, 0x9d, 0x6f, 0x75, 0xe8, 0x6b, 0xfd, 0x20, 0x6b, 0xf9, 0xf2, 0x20, 0xfa, 0x70, 0xec, 0x6c, 0x20, 0xef, 0xe1, 0x62, 0x65, 0x6c, 0x73, 0x6b, 0xe9, 0x20, 0xf3, 0x64, 0x79]);
const WIN1250_STRING = 'Příliš žluťoučký kůň úpěl ďábelské ódy';

export const routes = {
charset: {
path: '/charset',
bodyBuffer: Buffer.from([0x50, 0xf8, 0xed, 0x6c, 0x69, 0x9a, 0x20, 0x9e, 0x6c, 0x75, 0x9d, 0x6f, 0x75, 0xe8, 0x6b, 0xfd, 0x20, 0x6b, 0xf9, 0xf2, 0x20, 0xfa, 0x70, 0xec, 0x6c, 0x20, 0xef, 0xe1, 0x62, 0x65, 0x6c, 0x73, 0x6b, 0xe9, 0x20, 0xf3, 0x64, 0x79]),
bodyString: 'Příliš žluťoučký kůň úpěl ďábelské ódy'
bodyBuffer: WIN1250_BODY,
bodyString: WIN1250_STRING,
},
charsetMetaCharset: {
path: '/charset/meta-charset',
bodyString: WIN1250_STRING,
},
charsetMetaHttpEquiv: {
path: '/charset/meta-http-equiv',
bodyString: WIN1250_STRING,
},
}

Expand All @@ -18,6 +30,26 @@ export async function runServer(port: number): Promise<Server> {
res.send(routes.charset.bodyBuffer);
});

app.get(routes.charsetMetaCharset.path, (req, res) => {
const html = Buffer.concat([
Buffer.from('<html><head><meta charset="windows-1250"></head><body>'),
WIN1250_BODY,
Buffer.from('</body></html>'),
]);
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(html);
});

app.get(routes.charsetMetaHttpEquiv.path, (req, res) => {
const html = Buffer.concat([
Buffer.from('<html><head><meta http-equiv="content-type" content="text/html; charset=windows-1250"></head><body>'),
WIN1250_BODY,
Buffer.from('</body></html>'),
]);
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(html);
});

app.get('/socket', (req, res) => {
const socket = req.socket;
const clientAddress = socket.remoteAddress;
Expand Down
Loading