Skip to content

Commit

Permalink
refactor: fix typo in defineProxyMiddleware (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
gacek1123 committed Aug 24, 2023
1 parent b6bd4a8 commit 1ed43da
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/middleware/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ProxyMiddleware = (
) => void,
) => void | true;

export function defineProxyMiddlware(m: ProxyMiddleware) {
export function defineProxyMiddleware(m: ProxyMiddleware) {
return m;
}

Expand All @@ -27,6 +27,6 @@ export type ProxyOutgoingMiddleware = (
opts: ProxyServerOptions & { target: URL; forward: URL },
) => void | true;

export function defineProxyOutgoingMiddlware(m: ProxyOutgoingMiddleware) {
export function defineProxyOutgoingMiddleware(m: ProxyOutgoingMiddleware) {
return m;
}
10 changes: 5 additions & 5 deletions src/middleware/web-incoming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import httpNative from "node:http";
import httpsNative from "node:https";
import { getPort, hasEncryptedConnection, setupOutgoing } from "../_utils";
import { webOutgoingMiddleware } from "./web-outgoing";
import { ProxyMiddleware, defineProxyMiddlware } from "./_utils";
import { ProxyMiddleware, defineProxyMiddleware } from "./_utils";

const nativeAgents = { http: httpNative, https: httpsNative };

/**
* Sets `content-length` to '0' if request is of DELETE type.
*/
const deleteLength = defineProxyMiddlware((req) => {
const deleteLength = defineProxyMiddleware((req) => {
if (
(req.method === "DELETE" || req.method === "OPTIONS") &&
!req.headers["content-length"]
Expand All @@ -22,7 +22,7 @@ const deleteLength = defineProxyMiddlware((req) => {
/**
* Sets timeout in request socket if it was specified in options.
*/
const timeout = defineProxyMiddlware((req, res, options) => {
const timeout = defineProxyMiddleware((req, res, options) => {
if (options.timeout) {
req.socket.setTimeout(options.timeout);
}
Expand All @@ -31,7 +31,7 @@ const timeout = defineProxyMiddlware((req, res, options) => {
/**
* Sets `x-forwarded-*` headers if specified in config.
*/
const XHeaders = defineProxyMiddlware((req, res, options) => {
const XHeaders = defineProxyMiddleware((req, res, options) => {
if (!options.xfwd) {
return;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ const XHeaders = defineProxyMiddlware((req, res, options) => {
* just dies otherwise.
*
*/
const stream = defineProxyMiddlware(
const stream = defineProxyMiddleware(
(req, res, options, server, head, callback) => {
// And we begin!
server.emit("start", req, res, options.target || options.forward);
Expand Down
12 changes: 6 additions & 6 deletions src/middleware/web-outgoing.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { rewriteCookieProperty } from "../_utils";
import {
ProxyOutgoingMiddleware,
defineProxyOutgoingMiddlware,
defineProxyOutgoingMiddleware,
} from "./_utils";

const redirectRegex = /^201|30([1278])$/;

/**
* If is a HTTP 1.0 request, remove chunk headers
*/
const removeChunked = defineProxyOutgoingMiddlware((req, res, proxyRes) => {
const removeChunked = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
if (req.httpVersion === "1.0") {
delete proxyRes.headers["transfer-encoding"];
}
Expand All @@ -19,15 +19,15 @@ const removeChunked = defineProxyOutgoingMiddlware((req, res, proxyRes) => {
* If is a HTTP 1.0 request, set the correct connection header
* or if connection header not present, then use `keep-alive`
*/
const setConnection = defineProxyOutgoingMiddlware((req, res, proxyRes) => {
const setConnection = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
if (req.httpVersion === "1.0") {
proxyRes.headers.connection = req.headers.connection || "close";
} else if (req.httpVersion !== "2.0" && !proxyRes.headers.connection) {
proxyRes.headers.connection = req.headers.connection || "keep-alive";
}
});

const setRedirectHostRewrite = defineProxyOutgoingMiddlware(
const setRedirectHostRewrite = defineProxyOutgoingMiddleware(
(req, res, proxyRes, options) => {
if (
(options.hostRewrite || options.autoRewrite || options.protocolRewrite) &&
Expand Down Expand Up @@ -67,7 +67,7 @@ const setRedirectHostRewrite = defineProxyOutgoingMiddlware(
*
* @api private
*/
const writeHeaders = defineProxyOutgoingMiddlware(
const writeHeaders = defineProxyOutgoingMiddleware(
(req, res, proxyRes, options) => {
let rewriteCookieDomainConfig = options.cookieDomainRewrite;
let rewriteCookiePathConfig = options.cookiePathRewrite;
Expand Down Expand Up @@ -123,7 +123,7 @@ const writeHeaders = defineProxyOutgoingMiddlware(
/**
* Set the statusCode from the proxyResponse
*/
const writeStatusCode = defineProxyOutgoingMiddlware((req, res, proxyRes) => {
const writeStatusCode = defineProxyOutgoingMiddleware((req, res, proxyRes) => {
// From Node.js docs: response.writeHead(statusCode[, statusMessage][, headers])
if (proxyRes.statusMessage) {
// @ts-expect-error
Expand Down
8 changes: 4 additions & 4 deletions src/middleware/ws-incoming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
setupOutgoing,
setupSocket,
} from "../_utils";
import { ProxyMiddleware, defineProxyMiddlware } from "./_utils";
import { ProxyMiddleware, defineProxyMiddleware } from "./_utils";

/**
* WebSocket requests must have the `GET` method and
* the `upgrade:websocket` header
*/
const checkMethodAndHeader = defineProxyMiddlware((req, socket) => {
const checkMethodAndHeader = defineProxyMiddleware((req, socket) => {
if (req.method !== "GET" || !req.headers.upgrade) {
socket.destroy();
return true;
Expand All @@ -28,7 +28,7 @@ const checkMethodAndHeader = defineProxyMiddlware((req, socket) => {
/**
* Sets `x-forwarded-*` headers if specified in config.
*/
const XHeaders = defineProxyMiddlware((req, socket, options) => {
const XHeaders = defineProxyMiddleware((req, socket, options) => {
if (!options.xfwd) {
return;
}
Expand All @@ -51,7 +51,7 @@ const XHeaders = defineProxyMiddlware((req, socket, options) => {
* Does the actual proxying. Make the request and upgrade it
* send the Switching Protocols request and pipe the sockets.
*/
const stream = defineProxyMiddlware(
const stream = defineProxyMiddleware(
(req, socket, options, server, head, callback) => {
const createHttpHeader = function (line, headers) {
return (
Expand Down

0 comments on commit 1ed43da

Please sign in to comment.