SocksClient.createConnection વિનંતી કરેલ destination સાથે જોડાયેલ stream પરત આપે છે. HTTPS માટે તે stream એ HTTP વિનંતી વહન કરતાં પહેલાં હજી TLS handshake ની જરૂર છે.

import { SocksClient } from 'socks';
import tls from 'node:tls';

const targetHost = 'service.example';
const info = await SocksClient.createConnection({
  proxy: { host: 'proxy.example', port: 1080, type: 5 },
  command: 'connect',
  destination: { host: targetHost, port: 443 },
  timeout: 10000,
});
const secure = tls.connect({
  socket: info.socket,
  servername: targetHost,
});
secure.on('error', onTransportError);
secure.on('data', onResponseBytes);
secure.once('secureConnect', () => {
  secure.write(
    `GET /data HTTP/1.1\r\nHost: ${targetHost}\r\nConnection: close\r\n\r\n`
  );
});

SOCKS5 proxy યાદી proxy host અને port માટે ઉમેદવારો પૂરા પાડે છે. onTransportError અને onResponseBytes હાલની એપ્લિકેશનના છે; બીજાએ HTTP response stream parse કરવો પડે. TLS ડેટા ટુકડાઓ સ્વતંત્ર રીતે પૂર્ણ HTTP સંદેશા નથી.

servername એ destination નું DNS નામ છે. Node નું નીચલા સ્તરનું tls.connect ડિફોલ્ટ રીતે SNI સક્રિય કરતું નથી, અને proxy hostname એ વેબસાઇટની certificate identity નથી.

certificate verification ચાલુ રાખો. જોડાયેલ socket પૂરું પાડવાથી TLS identity જાળવીને વેબસાઇટ સાથે અલગ સીધું જોડાણ ખોલવાનું ટાળાય છે.

SOCKS timeout તે વાટાઘાટને મર્યાદિત કરે છે. પછીના TLS અને એપ્લિકેશન વિનિમય માટે હજી પણ કૉલરનો ઇચ્છિત timeout, રદ કરવું અને સફાઈ નીતિ જરૂરી છે.

સંબંધિત લેખો