(
draft: HttpRequestDraft,
options: HttpRequestPreviewOptions = {},
)
| 225 | } |
| 226 | |
| 227 | export function buildHttpPreview( |
| 228 | draft: HttpRequestDraft, |
| 229 | options: HttpRequestPreviewOptions = {}, |
| 230 | ): string { |
| 231 | const previewDraft = interpolateDraft(draft, options.variables) |
| 232 | const url = buildPreviewUrl(previewDraft) |
| 233 | const { host, target } = getHttpUrlParts(url) |
| 234 | const headers = getPreviewHeaders(previewDraft) |
| 235 | const lines = [`${previewDraft.method} ${target || '/'} HTTP/1.1`] |
| 236 | |
| 237 | if (host && !hasHeader(headers, 'host')) { |
| 238 | lines.push(`Host: ${host}`) |
| 239 | } |
| 240 | |
| 241 | for (const header of headers) { |
| 242 | lines.push(`${header.key}: ${header.value}`) |
| 243 | } |
| 244 | |
| 245 | const body = bodyLines(previewDraft) |
| 246 | if (body.length > 0) { |
| 247 | lines.push('', ...body) |
| 248 | } |
| 249 | |
| 250 | return lines.join('\n') |
| 251 | } |
| 252 | |
| 253 | export function buildCurlPreview( |
| 254 | draft: HttpRequestDraft, |
no test coverage detected