Skip to content

Commit

Permalink
fix ts errors in testing and a typing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 authored and joeferner committed Nov 26, 2023
1 parent 90bca40 commit d38a3a6
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 16 deletions.
10 changes: 7 additions & 3 deletions examples/forwardHttps.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const port = 8081;
import net from "net";
import assert from "assert";
import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();
import { exec } from "child_process";

proxy.onConnect((req, socket, head) => {
if (!req.url) {
console.log("No url in request");
return;
}
const host = req.url.split(":")[0];
const port = req.url.split(":")[1];
const port = parseInt(req.url.split(":")[1]);

console.log("Tunnel to", req.url);
const conn = net.connect(
Expand All @@ -23,7 +27,7 @@ proxy.onConnect((req, socket, head) => {
socket.on("close", () => {
conn.end();
});
socket.write("HTTP/1.1 200 OK\r\n\r\n", "UTF-8", () => {
socket.write("HTTP/1.1 200 OK\r\n\r\n", "utf-8", () => {
conn.pipe(socket);
socket.pipe(conn);
});
Expand Down
4 changes: 2 additions & 2 deletions examples/modifyGoogle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const port = 8081;

import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();

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

Expand Down
2 changes: 1 addition & 1 deletion examples/onCertificateMissing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const port = 8081;
import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();

proxy.onError((ctx, err, errorKind) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/onCertificateRequired.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const port = 8081;
import path from "path";
import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();

proxy.onError((ctx, err, errorKind) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/preventRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const port = 8081;

import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();

proxy.onError((ctx, err, errorKind) => {
Expand Down
7 changes: 4 additions & 3 deletions examples/processFullResponseBody.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const port = 8081;

import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();

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

proxy.onRequest((ctx, callback) => {
const chunks = [];
const chunks = new Array<Buffer>();
ctx.onResponseData((ctx, chunk, callback) => {
chunks.push(chunk);
return callback(null, null); // don't write chunks to client response
return callback(null, undefined); // don't write chunks to client response
});
ctx.onResponseEnd((ctx, callback) => {
let body: string | Buffer = Buffer.concat(chunks);
if (
ctx.serverToProxyResponse !== undefined &&
ctx.serverToProxyResponse.headers["content-type"] &&
ctx.serverToProxyResponse.headers["content-type"].indexOf("text/html") ===
0
Expand Down
7 changes: 5 additions & 2 deletions examples/removeProxyToServerContentLength.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const port = 8081;

import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();

proxy.onRequest((ctx, callback) => {
if ("content-length" in ctx.proxyToServerRequestOptions.headers) {
if (
ctx.proxyToServerRequestOptions !== undefined &&
"content-length" in ctx.proxyToServerRequestOptions.headers
) {
console.log(
`found "content-length" header in request to "${ctx.proxyToServerRequestOptions.host}${ctx.proxyToServerRequestOptions.path}". Removing.`
);
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const port = 8081;

import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();

proxy.onError((ctx, err, errorKind) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/wildcard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const port = 8081;

import Proxy from "../";
import { Proxy } from "../";
const proxy = new Proxy();

proxy.use(Proxy.wildcard);
Expand Down
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export type OnWebSocketCloseParams = (
export interface ICertDetails {
keyFile: string;
certFile: string;
hosts: string[];
hosts?: string[];
}

export type MaybeError = Error | null | undefined;
Expand Down

0 comments on commit d38a3a6

Please sign in to comment.