MCPcopy Create free account
hub / github.com/massCodeIO/massCode / buildCurlPreview

Function buildCurlPreview

src/renderer/components/http/requestPreview.ts:253–285  ·  view source on GitHub ↗
(
  draft: HttpRequestDraft,
  options: HttpRequestPreviewOptions = {},
)

Source from the content-addressed store, hash-verified

251}
252
253export function buildCurlPreview(
254 draft: HttpRequestDraft,
255 options: HttpRequestPreviewOptions = {},
256): string {
257 const previewDraft = interpolateDraft(draft, options.variables)
258 const url = buildPreviewUrl(previewDraft)
259 const indent = ' '
260 const lines = [
261 `curl -X ${shellDoubleQuote(previewDraft.method)} ${shellDoubleQuote(url)}`,
262 ]
263
264 for (const header of getPreviewHeaders(previewDraft)) {
265 lines.push(
266 `${indent}-H ${shellSingleQuote(`${header.key}: ${header.value}`)}`,
267 )
268 }
269
270 if (previewDraft.bodyType === 'multipart') {
271 for (const entry of previewDraft.formData.filter(entry => entry.key)) {
272 const value = entry.type === 'file' ? `@${entry.value}` : entry.value
273 lines.push(`${indent}-F ${shellSingleQuote(`${entry.key}=${value}`)}`)
274 }
275 }
276 else if (previewDraft.bodyType !== 'none' && previewDraft.body) {
277 lines.push(`${indent}-d ${shellAnsiCString(previewDraft.body)}`)
278 }
279
280 const command = lines
281 .map((line, index) => (index === lines.length - 1 ? line : `${line} \\`))
282 .join('\n')
283
284 return [`## ${previewDraft.name}`, command].join('\n')
285}
286
287export function buildRequestPreview(
288 draft: HttpRequestDraft,

Callers 2

buildRequestPreviewFunction · 0.85

Calls 6

interpolateDraftFunction · 0.85
buildPreviewUrlFunction · 0.85
shellDoubleQuoteFunction · 0.85
getPreviewHeadersFunction · 0.85
shellSingleQuoteFunction · 0.85
shellAnsiCStringFunction · 0.85

Tested by

no test coverage detected