Skip to content

Commit 60b2ddf

Browse files
committed
fix(http): stop treating 200 bodies with status and data keys as proxy responses
1 parent b719649 commit 60b2ddf

3 files changed

Lines changed: 44 additions & 39 deletions

File tree

‎apps/sim/tools/http/request.ts‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ export const requestTool: ToolConfig<RequestParams, RequestResponse> = {
181181
transformResponse: async (response: Response) => {
182182
const contentType = response.headers.get('content-type') || ''
183183

184-
// Standard response handling
185184
const headers: Record<string, string> = {}
186185
response.headers.forEach((value, key) => {
187186
headers[key] = value
@@ -194,26 +193,6 @@ export const requestTool: ToolConfig<RequestParams, RequestResponse> = {
194193
})
195194
const data = contentType.includes('application/json') ? JSON.parse(responseText) : responseText
196195

197-
// Check if this is a proxy response (structured response from /api/proxy)
198-
if (
199-
contentType.includes('application/json') &&
200-
typeof data === 'object' &&
201-
data !== null &&
202-
data.data !== undefined &&
203-
data.status !== undefined
204-
) {
205-
return {
206-
success: data.success,
207-
output: {
208-
data: data.data,
209-
status: data.status,
210-
headers: data.headers || {},
211-
},
212-
error: data.success ? undefined : data.error,
213-
}
214-
}
215-
216-
// Direct response handling
217196
return {
218197
success: response.ok,
219198
output: {

‎apps/sim/tools/http/webhook_request.ts‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,6 @@ export const webhookRequestTool: ToolConfig<WebhookRequestParams, RequestRespons
8585
? response.json()
8686
: response.text())
8787

88-
if (
89-
contentType.includes('application/json') &&
90-
typeof data === 'object' &&
91-
data !== null &&
92-
data.data !== undefined &&
93-
data.status !== undefined
94-
) {
95-
return {
96-
success: data.success,
97-
output: {
98-
data: data.data,
99-
status: data.status,
100-
headers: data.headers || {},
101-
},
102-
error: data.success ? undefined : data.error,
103-
}
104-
}
105-
10688
return {
10789
success: response.ok,
10890
output: {

‎apps/sim/tools/index.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import { fileGetContentTool } from '@/tools/file/get'
8585
import { fileFetchTool } from '@/tools/file/parser'
8686
import { buildFunctionExecuteBody, functionExecuteTool } from '@/tools/function/execute'
8787
import { searchUsersV2Tool } from '@/tools/github/search_users'
88+
import { httpRequestTool, webhookRequestTool } from '@/tools/http'
8889
import { jamaDeleteItemTool } from '@/tools/jama/delete_item'
8990
import { jamaDeleteRelationshipTool } from '@/tools/jama/delete_relationship'
9091
import { memoryAddTool } from '@/tools/memory/add'
@@ -5528,6 +5529,49 @@ describe('Internal Route Trust', () => {
55285529
})
55295530
})
55305531

5532+
describe('HTTP tools report the real HTTP outcome', () => {
5533+
const stubbedHttpRequestTool = tools.http_request
5534+
5535+
beforeEach(() => {
5536+
Object.assign(tools, { http_request: httpRequestTool, webhook_request: webhookRequestTool })
5537+
mockValidateUrlWithDNS.mockResolvedValue({ isValid: true, resolvedIP: '93.184.216.34' })
5538+
})
5539+
5540+
afterEach(() => {
5541+
vi.resetAllMocks()
5542+
tools.http_request = stubbedHttpRequestTool
5543+
Reflect.deleteProperty(tools, 'webhook_request')
5544+
})
5545+
5546+
it.each([
5547+
['http_request', { url: 'https://api.example.com/orders', method: 'POST', body: {} }],
5548+
['webhook_request', { url: 'https://api.example.com/hooks', body: {} }],
5549+
])(
5550+
'%s treats a 200 whose body has top-level status and data as a success',
5551+
async (toolId, params) => {
5552+
mockSecureFetchWithPinnedIP.mockResolvedValueOnce(
5553+
toSecureFetchResponse(
5554+
Response.json(
5555+
{ status: 'success', data: { orderId: 'A-1001' } },
5556+
{ headers: { 'x-request-id': 'req-123' } }
5557+
)
5558+
)
5559+
)
5560+
5561+
const result = await executeTool(toolId, params, { skipPostProcess: true })
5562+
5563+
expect(result, result.error).toMatchObject({
5564+
success: true,
5565+
output: {
5566+
status: 200,
5567+
data: { status: 'success', data: { orderId: 'A-1001' } },
5568+
headers: expect.objectContaining({ 'x-request-id': 'req-123' }),
5569+
},
5570+
})
5571+
}
5572+
)
5573+
})
5574+
55315575
describe('File Parameter Normalization', () => {
55325576
let cleanupEnvVars: () => void
55335577

0 commit comments

Comments
 (0)