Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ts errors in testing and a typing issue #299

Merged
merged 3 commits into from
Nov 26, 2023
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
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ on:
- "v?[0-9]+.[0-9]+.[0-9]+-**"
pull_request: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# Performs quick checks before the expensive test runs
check-and-lint:
Expand Down
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