@midwayjs/http-proxy 3.10.10 → 3.10.11

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.
@@ -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: any): (req: any, res: any, next: any) => Promise<any>;
8
- execProxy(ctx: any, req: any, res: any, next: any, isExpress: any): Promise<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;
@@ -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.getFrameworkType() === core_1.MidwayFrameworkType.WEB_EXPRESS) {
17
+ if (app.getNamespace() === 'express') {
18
18
  return async (req, res, next) => {
19
- return this.execProxy(req, req, res, next, true);
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, false);
27
+ return this.execProxy(ctx, req, ctx, next, isServerless);
27
28
  };
28
29
  }
29
30
  }
30
- async execProxy(ctx, req, res, next, isExpress) {
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 isStream = targetRes.on && targetRes.writable;
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: isStream ? 'stream' : 'arrayBuffer',
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 (isStream) {
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 (isStream) {
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.10",
3
+ "version": "3.10.11",
4
4
  "description": "Midway Component for http proxy",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -30,12 +30,12 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@midwayjs/core": "^3.10.10",
33
- "@midwayjs/express": "^3.10.10",
34
- "@midwayjs/faas": "^3.10.10",
35
- "@midwayjs/koa": "^3.10.10",
36
- "@midwayjs/mock": "^3.10.10",
37
- "@midwayjs/serverless-app": "^3.10.10",
38
- "@midwayjs/web": "^3.10.10"
33
+ "@midwayjs/express": "^3.10.11",
34
+ "@midwayjs/faas": "^3.10.11",
35
+ "@midwayjs/koa": "^3.10.11",
36
+ "@midwayjs/mock": "^3.10.11",
37
+ "@midwayjs/serverless-app": "^3.10.11",
38
+ "@midwayjs/web": "^3.10.11"
39
39
  },
40
- "gitHead": "93d333e82e75b6eb44ab83f74a378172508730d6"
40
+ "gitHead": "df0db0aaa0e3ff168204e3d5cf1c534dccc9b15e"
41
41
  }