-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: copy to curl, compact context menus
- Loading branch information
Showing
4 changed files
with
154 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { BurpItem } from "@/types/burp"; | ||
|
||
export function toCurl(item: BurpItem): string { | ||
const curl_parts: string[] = []; | ||
|
||
// Start with the curl command and method | ||
curl_parts.push(`curl --path-as-is -i -s -k -X $'${item.method}'`); | ||
|
||
// Parse the request headers and body from the decoded request | ||
const requestLines = item.request.decodedValue.split("\n"); | ||
const headers: Record<string, string> = {}; | ||
let bodyStartIndex = -1; | ||
let cookieHeader = ""; | ||
|
||
// Skip the first line as it's the request line | ||
for (let i = 1; i < requestLines.length; i++) { | ||
const line = requestLines[i].trim(); | ||
if (line === "") { | ||
bodyStartIndex = i + 1; | ||
break; | ||
} | ||
const [name, ...valueParts] = line.split(":"); | ||
if (name && valueParts.length > 0) { | ||
const headerName = name.trim(); | ||
const headerValue = valueParts.join(":").trim(); | ||
|
||
// Handle cookies separately | ||
if (headerName.toLowerCase() === "cookie") { | ||
cookieHeader = headerValue; | ||
} else { | ||
headers[headerName] = headerValue; | ||
} | ||
} | ||
} | ||
|
||
// Add headers to curl command (excluding Cookie header as we'll handle it separately) | ||
const headerParts: string[] = []; | ||
for (const [name, value] of Object.entries(headers)) { | ||
headerParts.push(`-H $'${name}: ${value}'`); | ||
} | ||
if (headerParts.length > 0) { | ||
curl_parts.push(headerParts.join(" ")); | ||
} | ||
|
||
// Add cookies in a single -b flag if they exist | ||
if (cookieHeader) { | ||
curl_parts.push(`-b $'${cookieHeader}'`); | ||
} | ||
|
||
// Handle request body if it exists | ||
if (bodyStartIndex !== -1) { | ||
const body = requestLines.slice(bodyStartIndex).join("\n").trim(); | ||
if (body) { | ||
const contentType = headers["content-type"] || headers["Content-Type"]; | ||
if (contentType?.includes("application/json")) { | ||
// If content type is JSON, try to parse and stringify to ensure proper formatting | ||
try { | ||
const jsonBody = JSON.parse(body); | ||
curl_parts.push(`--data $'${JSON.stringify(jsonBody)}'`); | ||
} catch { | ||
// If parsing fails, use the raw body | ||
curl_parts.push(`--data $'${body}'`); | ||
} | ||
} else { | ||
curl_parts.push(`--data $'${body}'`); | ||
} | ||
} | ||
} | ||
|
||
// Add the URL | ||
curl_parts.push(`$'${item.host.value}${item.url}'`); | ||
|
||
// Join with line continuation | ||
return curl_parts.join(" \\\n "); | ||
} |