|
1 | | -import { ClientRequest } from 'http'; |
2 | 1 | import type * as https from 'https'; |
3 | 2 | import type * as express from 'express'; |
4 | 3 | import type { Filter, Request, RequestHandler, Response, Options } from './types'; |
5 | 4 | import * as httpProxy from 'http-proxy'; |
6 | 5 | import { createConfig, Config } from './config-factory'; |
7 | | -import * as querystring from 'querystring'; |
8 | 6 | import * as contextMatcher from './context-matcher'; |
9 | 7 | import * as handlers from './_handlers'; |
10 | 8 | import { getArrow, getInstance } from './logger'; |
@@ -35,9 +33,6 @@ export class HttpProxyMiddleware { |
35 | 33 | // log errors for debug purpose |
36 | 34 | this.proxy.on('error', this.logError); |
37 | 35 |
|
38 | | - // fix proxied body if bodyParser is involved |
39 | | - this.proxy.on('proxyReq', this.fixBody); |
40 | | - |
41 | 36 | // https://github.com/chimurai/http-proxy-middleware/issues/19 |
42 | 37 | // expose function to upgrade externally |
43 | 38 | (this.middleware as any).upgrade = (req, socket, head) => { |
@@ -198,24 +193,4 @@ export class HttpProxyMiddleware { |
198 | 193 |
|
199 | 194 | this.logger.error(errorMessage, requestHref, targetHref, err.code || err, errReference); |
200 | 195 | }; |
201 | | - |
202 | | - private fixBody = (proxyReq: ClientRequest, req: Request) => { |
203 | | - if (!req.body || !Object.keys(req.body).length) { |
204 | | - return; |
205 | | - } |
206 | | - |
207 | | - const contentType = proxyReq.getHeader('Content-Type') as string; |
208 | | - const writeBody = (bodyData: string) => { |
209 | | - proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData)); |
210 | | - proxyReq.write(bodyData); |
211 | | - }; |
212 | | - |
213 | | - if (contentType.includes('application/json')) { |
214 | | - writeBody(JSON.stringify(req.body)); |
215 | | - } |
216 | | - |
217 | | - if (contentType === 'application/x-www-form-urlencoded') { |
218 | | - writeBody(querystring.stringify(req.body)); |
219 | | - } |
220 | | - }; |
221 | 196 | } |
0 commit comments