@api-client/core 0.18.12 → 0.18.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/browser.d.ts +0 -3
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +0 -3
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +2 -5
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +2 -5
- package/build/src/index.js.map +1 -1
- package/build/src/lib/logging/DefaultLogger.d.ts +14 -0
- package/build/src/lib/logging/DefaultLogger.d.ts.map +1 -1
- package/build/src/lib/logging/DefaultLogger.js +27 -0
- package/build/src/lib/logging/DefaultLogger.js.map +1 -1
- package/build/src/lib/logging/index.d.ts +4 -0
- package/build/src/lib/logging/index.d.ts.map +1 -0
- package/build/src/lib/logging/index.js +10 -0
- package/build/src/lib/logging/index.js.map +1 -0
- package/build/src/models/ClientCertificate.d.ts +1 -1
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/RequestConfig.d.ts +1 -1
- package/build/src/models/RequestConfig.js.map +1 -1
- package/build/src/models/SerializableError.d.ts +1 -1
- package/build/src/models/SerializableError.d.ts.map +1 -1
- package/build/src/models/SerializableError.js.map +1 -1
- package/build/src/proxy/RequestProxy.d.ts.map +1 -1
- package/build/src/proxy/RequestProxy.js +2 -2
- package/build/src/proxy/RequestProxy.js.map +1 -1
- package/build/src/runtime/http-engine/CoreEngine.d.ts +218 -139
- package/build/src/runtime/http-engine/CoreEngine.d.ts.map +1 -1
- package/build/src/runtime/http-engine/CoreEngine.js +716 -870
- package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
- package/build/src/runtime/http-engine/PayloadSupport.d.ts.map +1 -1
- package/build/src/runtime/http-engine/PayloadSupport.js +2 -1
- package/build/src/runtime/http-engine/PayloadSupport.js.map +1 -1
- package/build/src/runtime/http-engine/auth/AuthManager.d.ts +73 -0
- package/build/src/runtime/http-engine/auth/AuthManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/auth/AuthManager.js +186 -0
- package/build/src/runtime/http-engine/auth/AuthManager.js.map +1 -0
- package/build/src/runtime/http-engine/auth/index.d.ts +2 -0
- package/build/src/runtime/http-engine/auth/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/auth/index.js +2 -0
- package/build/src/runtime/http-engine/auth/index.js.map +1 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts +11 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.js +76 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.js.map +1 -0
- package/build/src/runtime/http-engine/certificates/index.d.ts +2 -0
- package/build/src/runtime/http-engine/certificates/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/certificates/index.js +2 -0
- package/build/src/runtime/http-engine/certificates/index.js.map +1 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.d.ts +25 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.js +89 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.js.map +1 -0
- package/build/src/runtime/http-engine/compression/index.d.ts +2 -0
- package/build/src/runtime/http-engine/compression/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/compression/index.js +2 -0
- package/build/src/runtime/http-engine/compression/index.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts +57 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.js +78 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.js.map +1 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts +70 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.js +184 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.js.map +1 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.d.ts +22 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.js +105 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts +60 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js +138 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts +14 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.js +47 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts +13 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.js +175 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/index.d.ts +7 -0
- package/build/src/runtime/http-engine/connections/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/index.js +7 -0
- package/build/src/runtime/http-engine/connections/index.js.map +1 -0
- package/build/src/runtime/http-engine/constants.d.ts +69 -0
- package/build/src/runtime/http-engine/constants.d.ts.map +1 -0
- package/build/src/runtime/http-engine/constants.js +90 -0
- package/build/src/runtime/http-engine/constants.js.map +1 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts +5 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.js +20 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/cookies/index.d.ts +2 -0
- package/build/src/runtime/http-engine/cookies/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/cookies/index.js +2 -0
- package/build/src/runtime/http-engine/cookies/index.js.map +1 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts +156 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts.map +1 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.js +227 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.js.map +1 -0
- package/build/src/runtime/http-engine/errors/index.d.ts +2 -0
- package/build/src/runtime/http-engine/errors/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/errors/index.js +2 -0
- package/build/src/runtime/http-engine/errors/index.js.map +1 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.d.ts +66 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.js +161 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.js.map +1 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.d.ts +27 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.js +51 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/message/index.d.ts +3 -0
- package/build/src/runtime/http-engine/message/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/index.js +3 -0
- package/build/src/runtime/http-engine/message/index.js.map +1 -0
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts +2 -8
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts.map +1 -1
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.js +11 -5
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.js.map +1 -1
- package/build/src/runtime/http-engine/ntlm/NtlmMessage.js +6 -6
- package/build/src/runtime/http-engine/ntlm/NtlmMessage.js.map +1 -1
- package/build/src/runtime/http-engine/parsers/BodyParser.d.ts +39 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.js +145 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts +29 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.js +88 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts +91 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.js +236 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.d.ts +20 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.js +51 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/index.d.ts +5 -0
- package/build/src/runtime/http-engine/parsers/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/index.js +5 -0
- package/build/src/runtime/http-engine/parsers/index.js.map +1 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts +22 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.js +25 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/response/index.d.ts +2 -0
- package/build/src/runtime/http-engine/response/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/response/index.js +2 -0
- package/build/src/runtime/http-engine/response/index.js.map +1 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts +7 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js +40 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/statistics/index.d.ts +2 -0
- package/build/src/runtime/http-engine/statistics/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/statistics/index.js +2 -0
- package/build/src/runtime/http-engine/statistics/index.js.map +1 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.d.ts +24 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.js +50 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/url/index.d.ts +2 -0
- package/build/src/runtime/http-engine/url/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/url/index.js +2 -0
- package/build/src/runtime/http-engine/url/index.js.map +1 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +3 -3
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts.map +1 -1
- package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.d.ts +3 -3
- package/build/src/runtime/node/InteropInterfaces.d.ts.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +2 -2
- package/build/src/runtime/node/ProjectRequestRunner.d.ts.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts.map +1 -1
- package/build/src/runtime/node/ProjectRunner.js +2 -2
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +6 -6
- package/package.json +2 -2
- package/src/lib/logging/DefaultLogger.ts +32 -0
- package/src/models/ClientCertificate.ts +1 -1
- package/src/models/RequestConfig.ts +1 -1
- package/src/models/SerializableError.ts +1 -1
- package/src/proxy/RequestProxy.ts +2 -2
- package/src/runtime/http-engine/CoreEngine.ts +858 -893
- package/src/runtime/http-engine/PayloadSupport.ts +2 -1
- package/src/runtime/http-engine/auth/AuthManager.ts +242 -0
- package/src/runtime/http-engine/certificates/CertificateManager.ts +74 -0
- package/src/runtime/http-engine/compression/CompressionManager.ts +99 -0
- package/src/runtime/http-engine/connections/ConnectionManager.ts +123 -0
- package/src/runtime/http-engine/connections/DigestAuthHandler.ts +238 -0
- package/src/runtime/http-engine/connections/DirectConnection.ts +134 -0
- package/src/runtime/http-engine/connections/ProxyAuthHandler.ts +179 -0
- package/src/runtime/http-engine/connections/ProxyConnection.ts +55 -0
- package/src/runtime/http-engine/connections/TunnelConnection.ts +192 -0
- package/src/runtime/http-engine/constants.ts +103 -0
- package/src/runtime/http-engine/cookies/CookieProcessor.ts +25 -0
- package/src/runtime/http-engine/errors/HttpEngineErrors.ts +319 -0
- package/src/runtime/http-engine/message/MessageBuilder.ts +201 -0
- package/src/runtime/http-engine/message/MessageProcessor.ts +73 -0
- package/src/runtime/http-engine/ntlm/NtlmAuth.ts +16 -13
- package/src/runtime/http-engine/ntlm/NtlmMessage.ts +6 -6
- package/src/runtime/http-engine/parsers/BodyParser.ts +171 -0
- package/src/runtime/http-engine/parsers/HeadersParser.ts +103 -0
- package/src/runtime/http-engine/parsers/HttpResponseParser.ts +280 -0
- package/src/runtime/http-engine/parsers/StatusParser.ts +69 -0
- package/src/runtime/http-engine/response/ResponseProcessor.ts +46 -0
- package/src/runtime/http-engine/statistics/StatisticsProcessor.ts +52 -0
- package/src/runtime/http-engine/url/UrlProcessor.ts +55 -0
- package/src/runtime/http-runner/HttpRequestRunner.ts +3 -3
- package/src/runtime/node/InteropInterfaces.ts +3 -3
- package/src/runtime/node/ProjectRequestRunner.ts +2 -2
- package/src/runtime/node/ProjectRunner.ts +2 -2
- package/tests/servers/ProxyServer.ts +32 -19
- package/tests/servers/express-routes/ApiEndpoint.ts +24 -0
- package/tests/servers/express-routes/BasicAuthRoute.ts +36 -0
- package/tests/servers/express-routes/BearerAuthRoute.ts +35 -0
- package/tests/servers/express-routes/NTLMRoute.ts +2 -3
- package/tests/servers/express-routes/PostApi.ts +15 -2
- package/tests/servers/express-routes/RedirectsApi.ts +12 -1
- package/tests/servers/express-routes/ResponsesApi.ts +1 -1
- package/tests/servers/express-routes/StreamApi.ts +19 -0
- package/tests/servers/oauth2mock/ServerMock.js +1 -1
- package/tests/unit/runtime/http-engine/HttpResponseParser.spec.ts +337 -0
- package/tests/unit/runtime/http-engine/abort.spec.ts +4 -5
- package/tests/unit/runtime/http-engine/auth.spec.ts +7 -58
- package/tests/unit/runtime/http-engine/certificates/CertificateManager.spec.ts +482 -0
- package/tests/unit/runtime/http-engine/certificates.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/compression/CompressionManager.spec.ts +498 -0
- package/tests/unit/runtime/http-engine/compression.spec.ts +3 -72
- package/tests/unit/runtime/http-engine/connections/ConnectionManager.spec.ts +379 -0
- package/tests/unit/runtime/http-engine/connections/DigestAuthHandler.spec.ts +164 -0
- package/tests/unit/runtime/http-engine/core_engine.spec.ts +561 -0
- package/tests/unit/runtime/http-engine/engine_statuses.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/events.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/headers.spec.ts +2 -88
- package/tests/unit/runtime/http-engine/hosts.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/http-get.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/http-post.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/logger.spec.ts +0 -8
- package/tests/unit/runtime/http-engine/message.spec.ts +2 -194
- package/tests/unit/runtime/http-engine/params.spec.ts +4 -4
- package/tests/unit/runtime/http-engine/proxy.spec.ts +15 -14
- package/tests/unit/runtime/http-engine/redirects.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/responses.spec.ts +170 -277
- package/tests/unit/runtime/http-engine/timeout.spec.ts +3 -3
- package/tests/unit/runtime/http-engine/timings.spec.ts +2 -2
- package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +25 -28
- package/tests/unit/runtime/runners/project_runner.spec.ts +2 -2
- package/tests/unit/runtime/runners/request_runner.spec.ts +2 -2
- package/build/src/runtime/http-engine/HttpEngine.d.ts +0 -311
- package/build/src/runtime/http-engine/HttpEngine.d.ts.map +0 -1
- package/build/src/runtime/http-engine/HttpEngine.js +0 -802
- package/build/src/runtime/http-engine/HttpEngine.js.map +0 -1
- package/src/runtime/http-engine/HttpEngine.ts +0 -952
- package/tests/unit/runtime/http-engine/connecting.spec.ts +0 -140
|
@@ -44,11 +44,13 @@ export class ProxyServer {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async start(httpPort: number, sslPort: number): Promise<void> {
|
|
47
|
+
this.log('Starting proxy server on ports', httpPort, sslPort)
|
|
47
48
|
await this.startHttp(httpPort)
|
|
48
49
|
await this.startHttps(sslPort)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
async stop(): Promise<void> {
|
|
53
|
+
this.log('Stopping proxy server...')
|
|
52
54
|
this.disconnectAll()
|
|
53
55
|
await this.stopHttp()
|
|
54
56
|
await this.stopHttps()
|
|
@@ -58,8 +60,8 @@ export class ProxyServer {
|
|
|
58
60
|
const server = http.createServer()
|
|
59
61
|
this.httpServer = server
|
|
60
62
|
server.on('connection', this.connectionCallback)
|
|
61
|
-
server.on('connect', this.connectCallback)
|
|
62
|
-
server.on('request', this.requestCallback)
|
|
63
|
+
server.on('connect', this.connectCallback)
|
|
64
|
+
server.on('request', this.requestCallback)
|
|
63
65
|
return new Promise((resolve) => {
|
|
64
66
|
server.listen(port, () => resolve())
|
|
65
67
|
})
|
|
@@ -119,20 +121,14 @@ export class ProxyServer {
|
|
|
119
121
|
* @param res Node's response object
|
|
120
122
|
*/
|
|
121
123
|
requestCallback(req: http.IncomingMessage, res: http.ServerResponse): void {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
'Content-Type': 'application/json',
|
|
125
|
-
})
|
|
126
|
-
res.write(JSON.stringify({ error: 'should not handle this path.' }))
|
|
127
|
-
res.end()
|
|
128
|
-
} else {
|
|
129
|
-
this.proxy(req, res)
|
|
130
|
-
}
|
|
124
|
+
this.log('Received request:', req.method, req.url)
|
|
125
|
+
this.proxy(req, res)
|
|
131
126
|
}
|
|
132
127
|
|
|
133
128
|
/**
|
|
134
129
|
*/
|
|
135
130
|
connectCallback(request: http.IncomingMessage, clientSocket: net.Socket, head: Buffer): void {
|
|
131
|
+
this.log('Received CONNECT request:', request.method, request.url)
|
|
136
132
|
if (!this.isAuthorizedProxy(request)) {
|
|
137
133
|
const messages = [
|
|
138
134
|
'HTTP/1.1 401 Unauthorized',
|
|
@@ -146,13 +142,13 @@ export class ProxyServer {
|
|
|
146
142
|
messages.push('')
|
|
147
143
|
const headersBuffer = Buffer.from(messages.join('\r\n'))
|
|
148
144
|
const message = Buffer.concat([headersBuffer, bodyBuffer, Buffer.from('\r\n\r\n')])
|
|
149
|
-
// console.log(message.toString('utf8'))
|
|
145
|
+
// console.log(message.toString('utf8'))
|
|
150
146
|
clientSocket.write(message)
|
|
151
147
|
clientSocket.end()
|
|
152
148
|
return
|
|
153
149
|
}
|
|
154
150
|
|
|
155
|
-
this.log('Opening
|
|
151
|
+
this.log('Opening SSL tunnel...')
|
|
156
152
|
clientSocket.setKeepAlive(true)
|
|
157
153
|
const { port, hostname } = new URL(`https://${request.url}`)
|
|
158
154
|
const targetPort = Number(port || 443)
|
|
@@ -162,11 +158,9 @@ export class ProxyServer {
|
|
|
162
158
|
const serverSocket = net.connect(targetPort, hostname)
|
|
163
159
|
clientSocket.on('data', (data) => {
|
|
164
160
|
this.log(`Tunneling Client -> Server: ${data.length} bytes`)
|
|
165
|
-
// data.toString().split('\n').forEach((line) => this.log(line));
|
|
166
161
|
})
|
|
167
162
|
serverSocket.on('data', (data) => {
|
|
168
163
|
this.log(`Tunneling Client <- Server: ${data.length} bytes`)
|
|
169
|
-
// data.toString().split('\n').forEach((line) => this.log(line));
|
|
170
164
|
})
|
|
171
165
|
serverSocket.once('end', () => {
|
|
172
166
|
this.log('Target socket ended.')
|
|
@@ -195,8 +189,9 @@ export class ProxyServer {
|
|
|
195
189
|
clientSocket.destroy()
|
|
196
190
|
serverSocket.destroy()
|
|
197
191
|
})
|
|
198
|
-
clientSocket.
|
|
199
|
-
this.log('Client socket
|
|
192
|
+
clientSocket.once('close', () => {
|
|
193
|
+
this.log('Client socket closed')
|
|
194
|
+
serverSocket.destroy()
|
|
200
195
|
})
|
|
201
196
|
serverSocket.setKeepAlive(true)
|
|
202
197
|
}
|
|
@@ -205,9 +200,15 @@ export class ProxyServer {
|
|
|
205
200
|
* Caches sockets after connection.
|
|
206
201
|
*/
|
|
207
202
|
connectionCallback(socket: net.Socket): void {
|
|
203
|
+
this.log('Connection established, caching socket.')
|
|
208
204
|
const socketKey = String(++this.lastSocketKey)
|
|
209
205
|
this.socketMap[socketKey] = socket
|
|
210
|
-
socket.
|
|
206
|
+
socket.once('close', () => {
|
|
207
|
+
this.log('Client socket closed, removing from cache:', socketKey)
|
|
208
|
+
const soc = this.socketMap[socketKey]
|
|
209
|
+
if (soc && !soc.destroyed) {
|
|
210
|
+
soc.destroy()
|
|
211
|
+
}
|
|
211
212
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
212
213
|
delete this.socketMap[socketKey]
|
|
213
214
|
})
|
|
@@ -220,6 +221,7 @@ export class ProxyServer {
|
|
|
220
221
|
* @param res Node's response object
|
|
221
222
|
*/
|
|
222
223
|
proxy(req: http.IncomingMessage, res: http.ServerResponse): void {
|
|
224
|
+
this.log('Proxying request:', req.method, req.url)
|
|
223
225
|
if (!req.url) {
|
|
224
226
|
res.writeHead(400, {
|
|
225
227
|
'Content-Type': 'application/json',
|
|
@@ -277,6 +279,7 @@ export class ProxyServer {
|
|
|
277
279
|
* @param sourceResponse Node's response object
|
|
278
280
|
*/
|
|
279
281
|
proxyHttp(sourceRequest: http.IncomingMessage, sourceResponse: http.ServerResponse): void {
|
|
282
|
+
this.log('Proxying HTTP request:', sourceRequest.method, sourceRequest.url)
|
|
280
283
|
if (!this.isAuthorizedProxy(sourceRequest)) {
|
|
281
284
|
sourceResponse.writeHead(401, {
|
|
282
285
|
'Content-Type': 'application/json',
|
|
@@ -296,7 +299,13 @@ export class ProxyServer {
|
|
|
296
299
|
protocol: urlInfo.protocol,
|
|
297
300
|
headers,
|
|
298
301
|
}
|
|
302
|
+
|
|
303
|
+
// Log the proxy request for debugging
|
|
304
|
+
this.log('Proxying request to:', urlInfo.href)
|
|
305
|
+
this.log('Target host:', urlInfo.host)
|
|
306
|
+
this.log('Target port:', urlInfo.port || 80)
|
|
299
307
|
const proxy = http.request(options, (targetResponse) => {
|
|
308
|
+
this.log('Received response from target:', targetResponse.statusCode)
|
|
300
309
|
if (targetResponse.statusCode) {
|
|
301
310
|
sourceResponse.statusCode = targetResponse.statusCode
|
|
302
311
|
}
|
|
@@ -326,6 +335,7 @@ export class ProxyServer {
|
|
|
326
335
|
})
|
|
327
336
|
}
|
|
328
337
|
proxy.on('error', (err) => {
|
|
338
|
+
this.log('Proxy error:', err.message)
|
|
329
339
|
if ((err as NodeJS.ErrnoException).code === 'ENOTFOUND') {
|
|
330
340
|
sourceResponse.writeHead(404)
|
|
331
341
|
sourceResponse.end()
|
|
@@ -348,13 +358,16 @@ export class ProxyServer {
|
|
|
348
358
|
if (!info || !info.toLowerCase().startsWith('basic')) {
|
|
349
359
|
return true
|
|
350
360
|
}
|
|
361
|
+
this.log('Proxy authorization header found:', info)
|
|
351
362
|
try {
|
|
352
363
|
const buff = Buffer.from(info.substring(6), 'base64')
|
|
353
364
|
const text = buff.toString('ascii')
|
|
354
365
|
const parts = text.split(':')
|
|
355
366
|
const [username, password] = parts
|
|
356
|
-
return username === '
|
|
367
|
+
return username === 'proxyuser' && password === 'proxypass'
|
|
357
368
|
} catch {
|
|
369
|
+
// eslint-disable-next-line no-console
|
|
370
|
+
console.error('Invalid proxy authorization:', info)
|
|
358
371
|
return false
|
|
359
372
|
}
|
|
360
373
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Router, Request, Response } from 'express'
|
|
2
|
+
import cors from 'cors'
|
|
3
|
+
import { BaseApi } from './BaseApi.js'
|
|
4
|
+
|
|
5
|
+
const router = Router()
|
|
6
|
+
export default router
|
|
7
|
+
|
|
8
|
+
class ApiEndpointRoute extends BaseApi {
|
|
9
|
+
async endpoint(req: Request, res: Response): Promise<void> {
|
|
10
|
+
res.setHeader('content-type', 'application/json')
|
|
11
|
+
res.json({
|
|
12
|
+
message: 'API endpoint reached',
|
|
13
|
+
method: req.method,
|
|
14
|
+
headers: req.headers,
|
|
15
|
+
url: req.url,
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const api = new ApiEndpointRoute()
|
|
21
|
+
api.setCors(router)
|
|
22
|
+
const checkCorsFn = api._processCors
|
|
23
|
+
router.get('/endpoint', cors(checkCorsFn), api.endpoint.bind(api))
|
|
24
|
+
router.post('/endpoint', cors(checkCorsFn), api.endpoint.bind(api))
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Router, Request, Response } from 'express'
|
|
2
|
+
import cors from 'cors'
|
|
3
|
+
import { BaseApi } from './BaseApi.js'
|
|
4
|
+
|
|
5
|
+
const router = Router()
|
|
6
|
+
export default router
|
|
7
|
+
|
|
8
|
+
class BasicAuthRoute extends BaseApi {
|
|
9
|
+
async resource(req: Request, res: Response): Promise<void> {
|
|
10
|
+
const authHeader = req.headers.authorization
|
|
11
|
+
|
|
12
|
+
if (!authHeader || !authHeader.startsWith('Basic ')) {
|
|
13
|
+
res.setHeader('WWW-Authenticate', 'Basic realm="Test Realm"')
|
|
14
|
+
res.status(401).json({ error: 'Authentication required' })
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Decode Basic auth credentials
|
|
19
|
+
const credentials = Buffer.from(authHeader.substring(6), 'base64').toString('utf8')
|
|
20
|
+
const [username, password] = credentials.split(':')
|
|
21
|
+
|
|
22
|
+
// Simple validation for test purposes
|
|
23
|
+
if (username === 'testuser' && password === 'testpass') {
|
|
24
|
+
res.setHeader('content-type', 'application/json')
|
|
25
|
+
res.json({ authenticated: true, username })
|
|
26
|
+
} else {
|
|
27
|
+
res.setHeader('WWW-Authenticate', 'Basic realm="Test Realm"')
|
|
28
|
+
res.status(401).json({ error: 'Invalid credentials' })
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const api = new BasicAuthRoute()
|
|
34
|
+
api.setCors(router)
|
|
35
|
+
const checkCorsFn = api._processCors
|
|
36
|
+
router.get('/resource', cors(checkCorsFn), api.resource.bind(api))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Router, Request, Response } from 'express'
|
|
2
|
+
import cors from 'cors'
|
|
3
|
+
import { BaseApi } from './BaseApi.js'
|
|
4
|
+
|
|
5
|
+
const router = Router()
|
|
6
|
+
export default router
|
|
7
|
+
|
|
8
|
+
class BearerAuthRoute extends BaseApi {
|
|
9
|
+
async resource(req: Request, res: Response): Promise<void> {
|
|
10
|
+
const authHeader = req.headers.authorization
|
|
11
|
+
|
|
12
|
+
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
|
13
|
+
res.setHeader('WWW-Authenticate', 'Bearer realm="Test Realm"')
|
|
14
|
+
res.status(401).json({ error: 'Authentication required' })
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Extract Bearer token
|
|
19
|
+
const token = authHeader.substring(7)
|
|
20
|
+
|
|
21
|
+
// Simple validation for test purposes
|
|
22
|
+
if (token === 'test-token-123') {
|
|
23
|
+
res.setHeader('content-type', 'application/json')
|
|
24
|
+
res.json({ authenticated: true, token })
|
|
25
|
+
} else {
|
|
26
|
+
res.setHeader('WWW-Authenticate', 'Bearer realm="Test Realm"')
|
|
27
|
+
res.status(401).json({ error: 'Invalid token' })
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const api = new BearerAuthRoute()
|
|
33
|
+
api.setCors(router)
|
|
34
|
+
const checkCorsFn = api._processCors
|
|
35
|
+
router.get('/resource', cors(checkCorsFn), api.resource.bind(api))
|
|
@@ -10,10 +10,9 @@ export default router
|
|
|
10
10
|
router.use(
|
|
11
11
|
ntlm({
|
|
12
12
|
debug: function () {
|
|
13
|
-
//
|
|
14
|
-
// console.log.apply(null, args);
|
|
13
|
+
// console.log(...arguments)
|
|
15
14
|
},
|
|
16
|
-
domain: '
|
|
15
|
+
domain: 'custom.com',
|
|
17
16
|
})
|
|
18
17
|
)
|
|
19
18
|
|
|
@@ -7,9 +7,22 @@ export default router
|
|
|
7
7
|
|
|
8
8
|
class PostApiRoute extends BaseApi {
|
|
9
9
|
async echoProperties(req: Request, res: Response): Promise<void> {
|
|
10
|
-
const { headers, query } = req
|
|
10
|
+
const { headers, query, method } = req
|
|
11
11
|
const body = await this.readRequestBuffer(req)
|
|
12
|
-
|
|
12
|
+
const bodyStr = body.toString('utf8')
|
|
13
|
+
|
|
14
|
+
// Try to parse as JSON if content-type is application/json
|
|
15
|
+
let parsedBody = bodyStr
|
|
16
|
+
if (headers['content-type']?.includes('application/json')) {
|
|
17
|
+
try {
|
|
18
|
+
parsedBody = JSON.parse(bodyStr)
|
|
19
|
+
} catch {
|
|
20
|
+
// If parsing fails, keep as string
|
|
21
|
+
parsedBody = bodyStr
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
res.send({ headers, query, method, body: parsedBody })
|
|
13
26
|
}
|
|
14
27
|
}
|
|
15
28
|
const api = new PostApiRoute()
|
|
@@ -110,7 +110,7 @@ class RedirectsApiRoute extends BaseApi {
|
|
|
110
110
|
}
|
|
111
111
|
res.setHeader('location', next)
|
|
112
112
|
// Set-Cookie: UserID=JohnDoe; Max-Age=3600; Version=1
|
|
113
|
-
res.setHeader('set-cookie', `redirect-${size}=true; Path
|
|
113
|
+
res.setHeader('set-cookie', `redirect-${size}=true; Path=/`)
|
|
114
114
|
res.setHeader('connection', 'close')
|
|
115
115
|
res.status(302)
|
|
116
116
|
res.send({
|
|
@@ -118,6 +118,16 @@ class RedirectsApiRoute extends BaseApi {
|
|
|
118
118
|
headers: req.headers,
|
|
119
119
|
})
|
|
120
120
|
}
|
|
121
|
+
|
|
122
|
+
async simpleRedirect(req: Request, res: Response): Promise<void> {
|
|
123
|
+
res.setHeader('location', '/v1/get')
|
|
124
|
+
res.setHeader('connection', 'close')
|
|
125
|
+
res.status(302)
|
|
126
|
+
res.send({
|
|
127
|
+
location: '/v1/get',
|
|
128
|
+
headers: req.headers,
|
|
129
|
+
})
|
|
130
|
+
}
|
|
121
131
|
}
|
|
122
132
|
const api = new RedirectsApiRoute()
|
|
123
133
|
api.setCors(router)
|
|
@@ -126,3 +136,4 @@ router.get('/absolute/:n', cors(checkCorsFn), api.absolute.bind(api))
|
|
|
126
136
|
router.get('/relative/:n', cors(checkCorsFn), api.relativePath.bind(api))
|
|
127
137
|
router.get('/relative-root/:n', cors(checkCorsFn), api.relative.bind(api))
|
|
128
138
|
router.get('/cookies/:n', cors(checkCorsFn), api.selfCookies.bind(api))
|
|
139
|
+
router.get('/', cors(checkCorsFn), api.simpleRedirect.bind(api))
|
|
@@ -2,7 +2,7 @@ import { Router, Request, Response } from 'express'
|
|
|
2
2
|
import cors from 'cors'
|
|
3
3
|
import { readFile } from 'fs/promises'
|
|
4
4
|
import path from 'path'
|
|
5
|
-
import crypto from 'crypto'
|
|
5
|
+
import crypto from 'node:crypto'
|
|
6
6
|
import { BaseApi } from './BaseApi.js'
|
|
7
7
|
|
|
8
8
|
const router = Router()
|
|
@@ -29,6 +29,24 @@ class StreamRoute extends BaseApi {
|
|
|
29
29
|
}, time)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
async chunked(req: Request, res: Response): Promise<void> {
|
|
33
|
+
res.writeHead(200, {
|
|
34
|
+
'Content-Type': 'text/plain; charset=UTF-8',
|
|
35
|
+
'Transfer-Encoding': 'chunked',
|
|
36
|
+
})
|
|
37
|
+
this.#writeChunk(res)
|
|
38
|
+
let time = 0
|
|
39
|
+
for (let i = 0; i < 4; i++) {
|
|
40
|
+
const timeout = this.#types.number({ min: 1, max: 10 })
|
|
41
|
+
time += timeout
|
|
42
|
+
setTimeout(() => this.#writeChunk(res), timeout)
|
|
43
|
+
}
|
|
44
|
+
time += 5
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
res.end('END')
|
|
47
|
+
}, time)
|
|
48
|
+
}
|
|
49
|
+
|
|
32
50
|
#writeChunk(res: Response): void {
|
|
33
51
|
const word = this.#lorem.word({ length: 128 })
|
|
34
52
|
res.write(`${word}\n`)
|
|
@@ -39,3 +57,4 @@ const api = new StreamRoute()
|
|
|
39
57
|
api.setCors(router)
|
|
40
58
|
const checkCorsFn = api._processCors
|
|
41
59
|
router.get('/', cors(checkCorsFn), api.index.bind(api))
|
|
60
|
+
router.get('/chunked', cors(checkCorsFn), api.chunked.bind(api))
|