({ req, finalUrl, requestBody, requestBodyPath, authHeader }: Input)
| 31 | authentication: {} | RequestAuthentication; |
| 32 | } |
| 33 | export const parseHeaderStrings = ({ req, finalUrl, requestBody, requestBodyPath, authHeader }: Input) => { |
| 34 | const headers = clone(req.headers); |
| 35 | |
| 36 | // Disable Expect and Transfer-Encoding headers when we have POST body/file |
| 37 | const hasRequestBodyOrFilePath = requestBody !== undefined || requestBodyPath; |
| 38 | if (hasRequestBodyOrFilePath) { |
| 39 | headers.push( |
| 40 | { name: 'Expect', value: DISABLE_HEADER_VALUE }, |
| 41 | { name: 'Transfer-Encoding', value: DISABLE_HEADER_VALUE }, |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | const { authentication, method } = req; |
| 46 | if (authentication && 'type' in authentication) { |
| 47 | const isDigest = authentication.type === 'digest'; |
| 48 | const isNTLM = authentication.type === 'ntlm'; |
| 49 | const isAWSIAM = authentication.type === 'iam'; |
| 50 | const hasNoAuthorisationAndNotDisabledAWSBasicOrDigest = |
| 51 | !hasAuthHeader(headers) && !authentication.disabled && !isAWSIAM && !isDigest && !isNTLM; |
| 52 | if (hasNoAuthorisationAndNotDisabledAWSBasicOrDigest && authHeader) { |
| 53 | headers.push(authHeader); |
| 54 | } |
| 55 | if (isAWSIAM) { |
| 56 | const hostHeader = getHostHeader(headers)?.value; |
| 57 | const contentTypeHeader = getContentTypeHeader(headers)?.value; |
| 58 | _getAwsAuthHeaders({ |
| 59 | authentication, |
| 60 | url: finalUrl, |
| 61 | hostHeader, |
| 62 | contentTypeHeader, |
| 63 | body: requestBody, |
| 64 | method, |
| 65 | }).forEach(header => headers.push(header)); |
| 66 | } |
| 67 | } |
| 68 | const isMultipartForm = req.body.mimeType === CONTENT_TYPE_FORM_DATA; |
| 69 | if (isMultipartForm && requestBodyPath) { |
| 70 | const contentTypeHeader = getContentTypeHeader(headers); |
| 71 | if (contentTypeHeader) { |
| 72 | contentTypeHeader.value = `multipart/form-data; boundary=${DEFAULT_BOUNDARY}`; |
| 73 | } else { |
| 74 | headers.push({ name: 'Content-Type', value: `multipart/form-data; boundary=${DEFAULT_BOUNDARY}` }); |
| 75 | } |
| 76 | } |
| 77 | // Send a default Accept headers of anything |
| 78 | if (!hasAcceptHeader(headers)) { |
| 79 | headers.push({ name: 'Accept', value: '*/*' }); // Default to anything |
| 80 | } |
| 81 | |
| 82 | // Don't auto-send Accept-Encoding header |
| 83 | if (!hasAcceptEncodingHeader(headers)) { |
| 84 | headers.push({ name: 'Accept-Encoding', value: DISABLE_HEADER_VALUE }); |
| 85 | } |
| 86 | |
| 87 | // Prevent curl from adding default content-type header |
| 88 | if (!hasContentTypeHeader(headers)) { |
| 89 | headers.push({ name: 'content-type', value: DISABLE_HEADER_VALUE }); |
| 90 | } |
no test coverage detected