Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions apps/sim/tools/http/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export const requestTool: ToolConfig<RequestParams, RequestResponse> = {
transformResponse: async (response: Response) => {
const contentType = response.headers.get('content-type') || ''

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

// Check if this is a proxy response (structured response from /api/proxy)
if (
contentType.includes('application/json') &&
typeof data === 'object' &&
data !== null &&
data.data !== undefined &&
data.status !== undefined
) {
return {
success: data.success,
output: {
data: data.data,
status: data.status,
headers: data.headers || {},
},
error: data.success ? undefined : data.error,
}
}

// Direct response handling
return {
success: response.ok,
output: {
Expand Down
18 changes: 0 additions & 18 deletions apps/sim/tools/http/webhook_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,6 @@ export const webhookRequestTool: ToolConfig<WebhookRequestParams, RequestRespons
? response.json()
: response.text())

if (
contentType.includes('application/json') &&
typeof data === 'object' &&
data !== null &&
data.data !== undefined &&
data.status !== undefined
) {
return {
success: data.success,
output: {
data: data.data,
status: data.status,
headers: data.headers || {},
},
error: data.success ? undefined : data.error,
}
}

return {
success: response.ok,
output: {
Expand Down
44 changes: 44 additions & 0 deletions apps/sim/tools/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import { fileGetContentTool } from '@/tools/file/get'
import { fileFetchTool } from '@/tools/file/parser'
import { buildFunctionExecuteBody, functionExecuteTool } from '@/tools/function/execute'
import { searchUsersV2Tool } from '@/tools/github/search_users'
import { httpRequestTool, webhookRequestTool } from '@/tools/http'
import { jamaDeleteItemTool } from '@/tools/jama/delete_item'
import { jamaDeleteRelationshipTool } from '@/tools/jama/delete_relationship'
import { memoryAddTool } from '@/tools/memory/add'
Expand Down Expand Up @@ -5528,6 +5529,49 @@ describe('Internal Route Trust', () => {
})
})

describe('HTTP tools report the real HTTP outcome', () => {
const stubbedHttpRequestTool = tools.http_request

beforeEach(() => {
Object.assign(tools, { http_request: httpRequestTool, webhook_request: webhookRequestTool })
mockValidateUrlWithDNS.mockResolvedValue({ isValid: true, resolvedIP: '93.184.216.34' })
})

afterEach(() => {
vi.resetAllMocks()
tools.http_request = stubbedHttpRequestTool
Reflect.deleteProperty(tools, 'webhook_request')
})

it.each([
['http_request', { url: 'https://api.example.com/orders', method: 'POST', body: {} }],
['webhook_request', { url: 'https://api.example.com/hooks', body: {} }],
])(
'%s treats a 200 whose body has top-level status and data as a success',
async (toolId, params) => {
mockSecureFetchWithPinnedIP.mockResolvedValueOnce(
toSecureFetchResponse(
Response.json(
{ status: 'success', data: { orderId: 'A-1001' } },
{ headers: { 'x-request-id': 'req-123' } }
)
)
)

const result = await executeTool(toolId, params, { skipPostProcess: true })

expect(result, result.error).toMatchObject({
success: true,
output: {
status: 200,
data: { status: 'success', data: { orderId: 'A-1001' } },
headers: expect.objectContaining({ 'x-request-id': 'req-123' }),
},
})
}
)
})

describe('File Parameter Normalization', () => {
let cleanupEnvVars: () => void

Expand Down