Skip to content

Commit 0bc70a9

Browse files
authored
Release 1.54.5 (#1279)
## Changes - fix: redirection to GET in Custom API
2 parents 656aa2c + e869fc5 commit 0bc70a9

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@
111111
"tsconfig-paths": "^4.2.0",
112112
"type-fest": "4.10.3"
113113
},
114-
"version": "1.54.4"
114+
"version": "1.54.5"
115115
}

packages/backend/src/apps/custom-api/__tests__/actions/http-request.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,14 @@ describe('make http request', () => {
163163
expect(mocks.httpRequest).toHaveBeenCalledTimes(2)
164164
})
165165

166-
it('should follow redirect with GET if 301 or 302', async () => {
166+
it('should follow redirect with GET if 301 or 302 without body and content-type header', async () => {
167167
mocks.isUrlAllowed.mockResolvedValueOnce(false)
168168
$.step.parameters.method = 'POST'
169169
$.step.parameters.data = 'meep meep'
170+
$.step.parameters.customHeaders = [
171+
{ key: 'Content-Type', value: 'plain/text' },
172+
{ key: 'Key2', value: 'Value2' },
173+
]
170174
$.step.parameters.url = 'http://test.local/endpoint?1234'
171175
mocks.httpRequest.mockResolvedValue({
172176
status: 301,
@@ -180,6 +184,10 @@ describe('make http request', () => {
180184
expect.objectContaining({
181185
url: 'http://test.local/endpoint?1234',
182186
method: 'POST',
187+
headers: {
188+
'Content-Type': 'plain/text',
189+
Key2: 'Value2',
190+
},
183191
data: 'meep meep',
184192
responseType: 'stream',
185193
}),
@@ -188,7 +196,9 @@ describe('make http request', () => {
188196
expect.objectContaining({
189197
url: 'https://redirect.com',
190198
method: 'GET',
191-
data: 'meep meep',
199+
headers: {
200+
Key2: 'Value2',
201+
},
192202
responseType: 'stream',
193203
}),
194204
)

packages/backend/src/apps/custom-api/actions/http-request/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ const action: IRawAction = {
100100

101101
async run($) {
102102
const method = $.step.parameters.method as TMethod
103-
const data = $.step.parameters.data as string
104103
const url = $.step.parameters.url as string
105104

106105
// Check if the step has an admin override for the timeout
@@ -149,14 +148,30 @@ const action: IRawAction = {
149148
if (!response.headers?.location) {
150149
throw new Error('No location header')
151150
}
151+
152+
// ref: https://github.com/follow-redirects/follow-redirects/blob/21ef28a544c5e57f4c34b8476d75f2144609a1eb/index.js#L442
153+
// if redirect method is GET, we need to delete the content-type header
154+
// and drop body
155+
// technically content-length header should also be dropped, but we dont set it
156+
// manually
157+
const redirectMethod =
158+
response.status === 301 || response.status === 302 ? 'GET' : method
159+
160+
const redirectHeaders = customHeaders ? { ...customHeaders } : {}
161+
if (redirectMethod === 'GET' && redirectHeaders) {
162+
delete redirectHeaders['content-type']
163+
delete redirectHeaders['Content-Type']
164+
}
165+
152166
response = await $.http.request({
153167
url: response.headers.location,
154-
method:
155-
response.status === 301 || response.status === 302 ? 'GET' : method,
156-
data,
168+
method: redirectMethod,
169+
// Only include data if the redirect method is not GET
170+
...(redirectMethod !== 'GET' && { data: parsedData }),
171+
headers: redirectHeaders,
172+
timeout,
157173
// Prevent calling of internal IPs, e.g. aws metadata endpoint
158174
lookup: safeAxiosLookup,
159-
headers: customHeaders,
160175
maxRedirects: 0,
161176
// stream the response for custom api to protect against gzip bombs
162177
responseType: 'stream',

packages/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frontend",
3-
"version": "1.54.4",
3+
"version": "1.54.5",
44
"type": "module",
55
"scripts": {
66
"dev": "wait-on tcp:3000 && vite --host --force",

packages/types/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"name": "@plumber/types",
33
"description": "Shared types for plumber",
44
"types": "./index.d.ts",
5-
"version": "1.54.4"
5+
"version": "1.54.5"
66
}

0 commit comments

Comments
 (0)