| 5 | import { Client } from '../../targets'; |
| 6 | |
| 7 | const getDecompressionMethods = (allHeaders: Request['allHeaders']) => { |
| 8 | let acceptEncodings = getHeader(allHeaders, 'accept-encoding'); |
| 9 | if (!acceptEncodings) { |
| 10 | return []; // no decompression |
| 11 | } |
| 12 | |
| 13 | const supportedMethods: Record<string, string> = { |
| 14 | gzip: 'DecompressionMethods.GZip', |
| 15 | deflate: 'DecompressionMethods.Deflate', |
| 16 | }; |
| 17 | |
| 18 | const methods: string[] = []; |
| 19 | if (typeof acceptEncodings === 'string') { |
| 20 | acceptEncodings = [acceptEncodings]; |
| 21 | } |
| 22 | acceptEncodings.forEach(acceptEncoding => { |
| 23 | acceptEncoding.split(',').forEach(encoding => { |
| 24 | const match = /\s*([^;\s]+)/.exec(encoding); |
| 25 | if (match) { |
| 26 | const method = supportedMethods[match[1]]; |
| 27 | if (method) { |
| 28 | methods.push(method); |
| 29 | } |
| 30 | } |
| 31 | }); |
| 32 | }); |
| 33 | |
| 34 | return methods; |
| 35 | }; |
| 36 | |
| 37 | export const httpclient: Client = { |
| 38 | info: { |