@midwayjs/http-proxy 3.10.10 → 3.10.12
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/dist/configuration.js +1 -1
- package/dist/middleware.d.ts +3 -3
- package/dist/middleware.js +9 -8
- package/package.json +9 -9
package/dist/configuration.js
CHANGED
package/dist/middleware.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { IMiddleware, IMidwayLogger } from '@midwayjs/core';
|
|
2
|
+
import { IMiddleware, IMidwayLogger, IMidwayApplication } from '@midwayjs/core';
|
|
3
3
|
import { HttpProxyConfig } from './interface';
|
|
4
4
|
export declare class HttpProxyMiddleware implements IMiddleware<any, any> {
|
|
5
5
|
httpProxy: HttpProxyConfig;
|
|
6
6
|
logger: IMidwayLogger;
|
|
7
|
-
resolve(app:
|
|
8
|
-
execProxy(ctx: any, req: any, res: any, next: any,
|
|
7
|
+
resolve(app: IMidwayApplication): (req: any, res: any, next: any) => Promise<any>;
|
|
8
|
+
execProxy(ctx: any, req: any, res: any, next: any, isServerless: any): Promise<any>;
|
|
9
9
|
getProxyList(url: any): undefined | {
|
|
10
10
|
proxy: HttpProxyConfig;
|
|
11
11
|
url: URL;
|
package/dist/middleware.js
CHANGED
|
@@ -14,20 +14,21 @@ const core_1 = require("@midwayjs/core");
|
|
|
14
14
|
const axios = require("axios");
|
|
15
15
|
let HttpProxyMiddleware = class HttpProxyMiddleware {
|
|
16
16
|
resolve(app) {
|
|
17
|
-
if (app.
|
|
17
|
+
if (app.getNamespace() === 'express') {
|
|
18
18
|
return async (req, res, next) => {
|
|
19
|
-
return this.execProxy(req, req, res, next,
|
|
19
|
+
return this.execProxy(req, req, res, next, false);
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
|
+
const isServerless = app.getNamespace() === 'faas';
|
|
23
24
|
return async (ctx, next) => {
|
|
24
25
|
var _a;
|
|
25
26
|
const req = ((_a = ctx.request) === null || _a === void 0 ? void 0 : _a.req) || ctx.request;
|
|
26
|
-
return this.execProxy(ctx, req, ctx, next,
|
|
27
|
+
return this.execProxy(ctx, req, ctx, next, isServerless);
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
async execProxy(ctx, req, res, next,
|
|
31
|
+
async execProxy(ctx, req, res, next, isServerless) {
|
|
31
32
|
var _a, _b, _c;
|
|
32
33
|
const proxyInfo = this.getProxyList(ctx.url);
|
|
33
34
|
if (!proxyInfo) {
|
|
@@ -50,12 +51,12 @@ let HttpProxyMiddleware = class HttpProxyMiddleware {
|
|
|
50
51
|
delete reqHeaders['content-length'];
|
|
51
52
|
const method = req.method.toUpperCase();
|
|
52
53
|
const targetRes = res.res || res;
|
|
53
|
-
const
|
|
54
|
+
const isSupportStream = !isServerless && targetRes.on && targetRes.writable;
|
|
54
55
|
const reqOptions = {
|
|
55
56
|
method,
|
|
56
57
|
url: url.href,
|
|
57
58
|
headers: reqHeaders,
|
|
58
|
-
responseType:
|
|
59
|
+
responseType: isSupportStream ? 'stream' : 'arrayBuffer',
|
|
59
60
|
timeout: this.httpProxy.proxyTimeout || 0,
|
|
60
61
|
};
|
|
61
62
|
if (method === 'POST' || method === 'PUT') {
|
|
@@ -77,7 +78,7 @@ let HttpProxyMiddleware = class HttpProxyMiddleware {
|
|
|
77
78
|
const ignoreHeaders = {
|
|
78
79
|
'transfer-encoding': true,
|
|
79
80
|
};
|
|
80
|
-
if (
|
|
81
|
+
if (isSupportStream) {
|
|
81
82
|
// axios does not set this real data length in stream mode
|
|
82
83
|
// but it decompresses the data, resulting in the wrong data length
|
|
83
84
|
ignoreHeaders['content-length'] = true;
|
|
@@ -89,7 +90,7 @@ let HttpProxyMiddleware = class HttpProxyMiddleware {
|
|
|
89
90
|
res.set(key, proxyResponse.headers[key]);
|
|
90
91
|
});
|
|
91
92
|
res.status = proxyResponse.status;
|
|
92
|
-
if (
|
|
93
|
+
if (isSupportStream) {
|
|
93
94
|
await new Promise(resolve => {
|
|
94
95
|
proxyResponse.data.on('finish', () => {
|
|
95
96
|
if (targetRes.end) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/http-proxy",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.12",
|
|
4
4
|
"description": "Midway Component for http proxy",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"axios": "1.3.
|
|
29
|
+
"axios": "1.3.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@midwayjs/core": "^3.10.10",
|
|
33
|
-
"@midwayjs/express": "^3.10.
|
|
34
|
-
"@midwayjs/faas": "^3.10.
|
|
35
|
-
"@midwayjs/koa": "^3.10.
|
|
36
|
-
"@midwayjs/mock": "^3.10.
|
|
37
|
-
"@midwayjs/serverless-app": "^3.10.
|
|
38
|
-
"@midwayjs/web": "^3.10.
|
|
33
|
+
"@midwayjs/express": "^3.10.11",
|
|
34
|
+
"@midwayjs/faas": "^3.10.12",
|
|
35
|
+
"@midwayjs/koa": "^3.10.11",
|
|
36
|
+
"@midwayjs/mock": "^3.10.11",
|
|
37
|
+
"@midwayjs/serverless-app": "^3.10.12",
|
|
38
|
+
"@midwayjs/web": "^3.10.11"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "5fbc455a226942afc49bf414fcdbd2ef88d3db96"
|
|
41
41
|
}
|