Skip to content

Commit d38a3a6

Browse files
Apollon77joeferner
authored andcommitted
fix ts errors in testing and a typing issue
1 parent 90bca40 commit d38a3a6

File tree

10 files changed

+24
-16
lines changed

10 files changed

+24
-16
lines changed

examples/forwardHttps.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
const port = 8081;
22
import net from "net";
33
import assert from "assert";
4-
import Proxy from "../";
4+
import { Proxy } from "../";
55
const proxy = new Proxy();
66
import { exec } from "child_process";
77

88
proxy.onConnect((req, socket, head) => {
9+
if (!req.url) {
10+
console.log("No url in request");
11+
return;
12+
}
913
const host = req.url.split(":")[0];
10-
const port = req.url.split(":")[1];
14+
const port = parseInt(req.url.split(":")[1]);
1115

1216
console.log("Tunnel to", req.url);
1317
const conn = net.connect(
@@ -23,7 +27,7 @@ proxy.onConnect((req, socket, head) => {
2327
socket.on("close", () => {
2428
conn.end();
2529
});
26-
socket.write("HTTP/1.1 200 OK\r\n\r\n", "UTF-8", () => {
30+
socket.write("HTTP/1.1 200 OK\r\n\r\n", "utf-8", () => {
2731
conn.pipe(socket);
2832
socket.pipe(conn);
2933
});

examples/modifyGoogle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const port = 8081;
22

3-
import Proxy from "../";
3+
import { Proxy } from "../";
44
const proxy = new Proxy();
55

66
proxy.onError((ctx, err, errorKind) => {
@@ -13,7 +13,7 @@ proxy.onRequest((ctx, callback) => {
1313
//console.log('REQUEST: http://' + ctx.clientToProxyRequest.headers.host + ctx.clientToProxyRequest.url);
1414
if (
1515
ctx.clientToProxyRequest.headers.host == "www.google.com" &&
16-
ctx.clientToProxyRequest.url.indexOf("/search") == 0
16+
ctx.clientToProxyRequest.url?.indexOf("/search") == 0
1717
) {
1818
ctx.use(Proxy.gunzip);
1919

examples/onCertificateMissing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const port = 8081;
2-
import Proxy from "../";
2+
import { Proxy } from "../";
33
const proxy = new Proxy();
44

55
proxy.onError((ctx, err, errorKind) => {

examples/onCertificateRequired.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const port = 8081;
22
import path from "path";
3-
import Proxy from "../";
3+
import { Proxy } from "../";
44
const proxy = new Proxy();
55

66
proxy.onError((ctx, err, errorKind) => {

examples/preventRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const port = 8081;
22

3-
import Proxy from "../";
3+
import { Proxy } from "../";
44
const proxy = new Proxy();
55

66
proxy.onError((ctx, err, errorKind) => {

examples/processFullResponseBody.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const port = 8081;
22

3-
import Proxy from "../";
3+
import { Proxy } from "../";
44
const proxy = new Proxy();
55

66
proxy.onError((ctx, err, errorKind) => {
@@ -13,14 +13,15 @@ proxy.onError((ctx, err, errorKind) => {
1313
proxy.use(Proxy.gunzip);
1414

1515
proxy.onRequest((ctx, callback) => {
16-
const chunks = [];
16+
const chunks = new Array<Buffer>();
1717
ctx.onResponseData((ctx, chunk, callback) => {
1818
chunks.push(chunk);
19-
return callback(null, null); // don't write chunks to client response
19+
return callback(null, undefined); // don't write chunks to client response
2020
});
2121
ctx.onResponseEnd((ctx, callback) => {
2222
let body: string | Buffer = Buffer.concat(chunks);
2323
if (
24+
ctx.serverToProxyResponse !== undefined &&
2425
ctx.serverToProxyResponse.headers["content-type"] &&
2526
ctx.serverToProxyResponse.headers["content-type"].indexOf("text/html") ===
2627
0

examples/removeProxyToServerContentLength.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const port = 8081;
22

3-
import Proxy from "../";
3+
import { Proxy } from "../";
44
const proxy = new Proxy();
55

66
proxy.onRequest((ctx, callback) => {
7-
if ("content-length" in ctx.proxyToServerRequestOptions.headers) {
7+
if (
8+
ctx.proxyToServerRequestOptions !== undefined &&
9+
"content-length" in ctx.proxyToServerRequestOptions.headers
10+
) {
811
console.log(
912
`found "content-length" header in request to "${ctx.proxyToServerRequestOptions.host}${ctx.proxyToServerRequestOptions.path}". Removing.`
1013
);

examples/websocket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const port = 8081;
22

3-
import Proxy from "../";
3+
import { Proxy } from "../";
44
const proxy = new Proxy();
55

66
proxy.onError((ctx, err, errorKind) => {

examples/wildcard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const port = 8081;
22

3-
import Proxy from "../";
3+
import { Proxy } from "../";
44
const proxy = new Proxy();
55

66
proxy.use(Proxy.wildcard);

lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export type OnWebSocketCloseParams = (
9191
export interface ICertDetails {
9292
keyFile: string;
9393
certFile: string;
94-
hosts: string[];
94+
hosts?: string[];
9595
}
9696

9797
export type MaybeError = Error | null | undefined;

0 commit comments

Comments
 (0)