Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
17hz authored Aug 12, 2024
2 parents 4b68c5c + 897611a commit 81e14e2
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 271 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- ci(package): npm package provenance
- fix(logger-plugin): log target port when router option is used
- refactor: fix circular dependencies
- fix(fix-request-body): support '+json' content-type suffix

## [v3.0.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v3.0.0)

Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"browser-sync": "3.0.2",
"connect": "3.7.0",
"express": "4.19.2",
"fastify": "4.27.0"
"fastify": "4.28.1"
}
}
196 changes: 91 additions & 105 deletions examples/yarn.lock

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-proxy-middleware",
"version": "3.0.1-beta.0",
"version": "3.0.1-beta.1",
"description": "The one-liner node.js proxy middleware for connect, express, next.js and more",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -28,7 +28,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/chimurai/http-proxy-middleware.git"
"url": "git+https://github.com/chimurai/http-proxy-middleware.git"
},
"keywords": [
"reverse",
Expand All @@ -55,18 +55,18 @@
},
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
"devDependencies": {
"@commitlint/cli": "19.2.1",
"@commitlint/config-conventional": "19.1.0",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@types/debug": "4.1.12",
"@types/express": "4.17.21",
"@types/is-glob": "4.0.4",
"@types/jest": "29.5.12",
"@types/micromatch": "4.0.6",
"@types/node": "20.12.5",
"@types/micromatch": "4.0.9",
"@types/node": "20.14.10",
"@types/supertest": "6.0.2",
"@types/ws": "8.5.10",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"@typescript-eslint/eslint-plugin": "7.16.0",
"@typescript-eslint/parser": "7.16.0",
"body-parser": "1.20.2",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
Expand All @@ -75,18 +75,18 @@
"get-port": "5.1.1",
"husky": "9.0.11",
"jest": "29.7.0",
"lint-staged": "15.2.5",
"mockttp": "3.10.2",
"lint-staged": "15.2.7",
"mockttp": "3.14.0",
"open": "8.4.2",
"prettier": "3.2.5",
"supertest": "6.3.4",
"ts-jest": "29.1.2",
"typescript": "5.4.4",
"ws": "8.16.0"
"prettier": "3.3.2",
"supertest": "7.0.0",
"ts-jest": "29.2.2",
"typescript": "5.5.3",
"ws": "8.18.0"
},
"dependencies": {
"@types/http-proxy": "^1.17.14",
"debug": "^4.3.4",
"debug": "^4.3.5",
"http-proxy": "^1.18.1",
"is-glob": "^4.0.3",
"is-plain-obj": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/fix-request-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function fixRequestBody<TReq = http.IncomingMessage>(
proxyReq.write(bodyData);
};

if (contentType && contentType.includes('application/json')) {
if (contentType && (contentType.includes('application/json') || contentType.includes('+json'))) {
writeBody(JSON.stringify(requestBody));
}

Expand Down
14 changes: 14 additions & 0 deletions test/unit/fix-request-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ describe('fixRequestBody', () => {
expect(proxyRequest.write).toHaveBeenCalledWith(expectedBody);
});

it('should write when body is not empty and Content-Type ends with +json', () => {
const proxyRequest = fakeProxyRequest();
proxyRequest.setHeader('content-type', 'application/merge-patch+json; charset=utf-8');

jest.spyOn(proxyRequest, 'setHeader');
jest.spyOn(proxyRequest, 'write');

fixRequestBody(proxyRequest, createRequestWithBody({ someField: 'some value' }));

const expectedBody = JSON.stringify({ someField: 'some value' });
expect(proxyRequest.setHeader).toHaveBeenCalledWith('Content-Length', expectedBody.length);
expect(proxyRequest.write).toHaveBeenCalledWith(expectedBody);
});

it('should write when body is not empty and Content-Type is application/x-www-form-urlencoded', () => {
const proxyRequest = fakeProxyRequest();
proxyRequest.setHeader('content-type', 'application/x-www-form-urlencoded');
Expand Down
Loading

0 comments on commit 81e14e2

Please sign in to comment.