| 31 | // tslint:disable-next-line:max-line-length |
| 32 | // https://github.com/facebook/react-native/blob/0ee5f68929610106ee6864baa04ea90be0fc5160/Libraries/vendor/core/whatwg-fetch.js#L421 |
| 33 | function parseHeaders(rawHeaders: string) { |
| 34 | const headers = new Headers(); |
| 35 | // Replace instances of \r\n and \n followed by at least one space or |
| 36 | // horizontal tab with a space https://tools.ietf.org/html/rfc7230#section-3.2 |
| 37 | const preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " "); |
| 38 | preProcessedHeaders.split(/\r?\n/).forEach((line) => { |
| 39 | const parts = line.split(":"); |
| 40 | const key = parts.shift().trim(); |
| 41 | if (key) { |
| 42 | const value = parts.join(":").trim(); |
| 43 | headers.append(key, value); |
| 44 | } |
| 45 | }); |
| 46 | return headers; |
| 47 | } |
| 48 | |
| 49 | // Implementation note: This is a patch of react-native's fetch implementation |
| 50 | // tslint:disable-next-line:max-line-length |