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

Add support forward req headers (#14) fix #13 #15

Merged
merged 1 commit into from
Oct 31, 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
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ BLOCKED_PUBKEYS=
WHITELISTED_PUBKEYS=
# Set true to filter proxy events
FILTER_PROXY_EVENTS=
# Set true to enable forwarding of request headers to upstream server
ENABLE_FORWARD_REQ_HEADERS=false
# Use classification result from monitoring bot as filter data
NOSTR_MONITORING_BOT_PUBLIC_KEY=
8 changes: 7 additions & 1 deletion filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ const whitelistedPubkeys: string[] =
: [];
// Filter proxy events
const filterProxyEvents = process.env.FILTER_PROXY_EVENTS === "true";
// Forward request headers to upstream
const enableForwardReqHeaders = process.env.ENABLE_FORWARD_REQ_HEADERS === "true";

// クライアントIPアドレスのCIDRフィルタ
const cidrRanges: string[] = [
Expand Down Expand Up @@ -487,8 +489,12 @@ async function listen(): Promise<void> {
// ソケットごとにユニークなIDを付与
const socketId = uuidv4();

// Check whether we want to forward original request headers to the upstream server
// This will be useful if the upstream server need original request headers to do operations like rate-limiting, etc.
let wsClientOptions = enableForwardReqHeaders ? { headers: req.headers } : undefined;

// 上流となるリレーサーバーと接続
let upstreamSocket = new WebSocket(upstreamWsUrl);
let upstreamSocket = new WebSocket(upstreamWsUrl, wsClientOptions);
connectUpstream(upstreamSocket, downstreamSocket);

// クライアントとの接続が確立したら、アイドルタイムアウトを設定
Expand Down