Skip to content

MA-22157: fix header parser and pinned stable yarn version #68

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions .github/actions/bump-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ inputs:

outputs:
prev_version:
description: Previous version of the package before bumping
value: ${{ steps.internal_id_prev_version.outputs.value }}
next_version:
description: New version of the package after bumping
value: ${{ steps.internal_id_next_version.outputs.value }}

runs:
Expand All @@ -24,13 +26,12 @@ runs:
shell: bash

- name: Bump version
if: ${{ !inputs.npm_tag }}
run: yarn version --new-version "${{ inputs.version }}" --no-commit-hooks
run: yarn version ${{ inputs.version }} --deferred
shell: bash

- name: Bump version with npm_tag
if: ${{ inputs.npm_tag }}
run: yarn version --new-version "${{ inputs.version }}" --preid ${{ inputs.npm_tag }} --no-commit-hooks
run: yarn version apply --${{ inputs.version }}=${{ inputs.npm_tag }}
shell: bash

- name: Saving new version to env
Expand Down
8 changes: 4 additions & 4 deletions .github/actions/complete-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ runs:

- name: Publishing release
if: ${{ !inputs.npm_tag }}
run: yarn publish --access public --non-interactive
run: yarn npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ inputs.npm_token }}
YARN_NPM_AUTH_TOKEN: ${{ inputs.npm_token }}
shell: bash

- name: Publishing release with npm_tag
if: ${{ inputs.npm_tag }}
run: yarn publish --access public --non-interactive --tag ${{ inputs.npm_tag }}
run: yarn npm publish --access public --tag ${{ inputs.npm_tag }}
env:
NODE_AUTH_TOKEN: ${{ inputs.npm_token }}
YARN_NPM_AUTH_TOKEN: ${{ inputs.npm_token }}
shell: bash
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runs:
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn install --frozen-lockfile --ignore-scripts
run: yarn install --frozen-lockfile
shell: bash

- name: Set Git credentials
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}

- name: Setting up the repository environment
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish_prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.DEVTOOLS_GITHUB_TOKEN }}

- name: Setting up the repository environment
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ coverage
# GitHub
.github/*

.yarn/

/bin
Binary file added .yarn/install-state.gz
Binary file not shown.
934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.5.3.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.3.cjs
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.2.6

- Исправлены проблемы с обработкой `cookies` в проксировании.

## v0.2.5

- Исправили замечания `npm audit`:
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "@vkontakte/vk-tunnel",
"license": "MIT",
"version": "0.2.5",
"bin": {
"vk-tunnel": "./bin/vk-tunnel.js"
},
"version": "0.2.6-0-beta",
"bin": "./bin/vk-tunnel.js",
"scripts": {
"build": "tsc && esbuild src/vk-tunnel.ts --bundle --platform=node --target=node16.0 --outfile=bin/vk-tunnel.js",
"lint:eslint": "eslint ./src --ext=ts",
Expand Down Expand Up @@ -48,5 +46,6 @@
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^2.7.1",
"typescript": "5.1.6"
}
},
"packageManager": "yarn@4.5.3"
}
6 changes: 5 additions & 1 deletion src/api/fetchTunnelData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export async function fetchTunnelData({
staging,
endpoints,
}: FetchTunnelDataRequest) {
const params: Record<string, string | number | boolean> = { access_token, version, v };
const params: Record<string, string | number | boolean> = {
access_token,
version,
v,
};

if (app_id) params['app_id'] = app_id;
if (staging) params['staging'] = staging;
Expand Down
18 changes: 12 additions & 6 deletions src/entities/HttpProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class HttpProxy {
return await axios({
url: proxiedServerUrl,
data: parsedRequest.body,
maxRedirects: 0,
headers: parsedRequest.headers,
method: parsedRequest.method as Method,
responseType: 'arraybuffer',
Expand All @@ -24,25 +25,30 @@ export class HttpProxy {

private generateHeadersForVkTunnelBack(proxiedServerResponse: AxiosResponse) {
let rawResponse = `HTTP/1.1 ${proxiedServerResponse.status} ${proxiedServerResponse.statusText}\r\n`;
let keys = Object.keys(proxiedServerResponse.headers);

for (let i = 0; i < keys.length; i++) {
if (keys[i] === 'transfer-encoding') {
for (const [key, value] of Object.entries(proxiedServerResponse.headers)) {
if (key === 'transfer-encoding') {
continue;
}

if (
keys[i] === 'content-length' &&
key === 'content-length' &&
proxiedServerResponse.headers.hasOwnProperty('transfer-encoding')
) {
rawResponse += `content-length: ${proxiedServerResponse.data.length}\r\n`;
continue;
}
rawResponse += `${keys[i]}:${proxiedServerResponse.headers[keys[i]]}\r\n`;

if (Array.isArray(value)) {
for (const val of value) {
rawResponse += `${key}: ${val}\r\n`;
}
} else {
rawResponse += `${key}: ${value}\r\n`;
}
}

rawResponse += '\r\n';

return rawResponse;
}

Expand Down
2 changes: 1 addition & 1 deletion src/entities/TunnelClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class TunnelClient {
this.socket.send(data, callback);
}

private transformPayload(payload: Buffer[] | ArrayBuffer) {
private transformPayload(payload: Buffer[] | ArrayBuffer | Buffer) {
return payload
.toString()
.replace(/Accept-Encoding:.*/, this.ACCEPT_ENCODING + ': ' + this.DISABLE_COMPRESS)
Expand Down
7 changes: 6 additions & 1 deletion src/entities/WsProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export class WsProxy {
websocket.on('message', (data, isBinary) => {
logger.debug('incoming ws message from service', seq, data, isBinary);

const dataBuf = Array.isArray(data) ? Buffer.concat(data) : Buffer.from(data);
const dataBuf = Array.isArray(data)
? Buffer.concat(data)
: Buffer.isBuffer(data)
? data
: Buffer.from(new Uint8Array(data));

const seqBuf = Buffer.from(seq, 'utf8');
const typeBuf = Buffer.from(MessageTypeToSend.WEBSOCKET, 'utf8');
const stringMessage = `${seq}${MessageTypeToSend.WEBSOCKET}${data}`;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface UserData {

export interface ProxiedNetworkPacket {
seq: string;
payload: ArrayBuffer | Buffer[] | string;
payload: ArrayBuffer | Buffer[] | string | Buffer;
endpoint: string;
messageType: MessageTypeFromBack;
isWebsocketUpgrade: boolean;
Expand Down
5 changes: 4 additions & 1 deletion src/vk-tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ async function vkTunnel() {
const vkProxyServerUrl = `${tunnelData.tunnelHost}/${tunnelData.url}`;

const socket = new WebsocketClient(vkProxyServerUrl, {
headers: { UserID: String(tunnelData.userId), Token: tunnelData.tunnelToken },
headers: {
UserID: String(tunnelData.userId),
Token: tunnelData.tunnelToken,
},
});

const tunnelClient = new TunnelClient(socket, tunnelData, userSettings);
Expand Down
Loading