source: frontend/node_modules/axios/lib/helpers/parseHeaders.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2
3import utils from '../utils.js';
4
5// RawAxiosHeaders whose duplicates are ignored by node
6// c.f. https://nodejs.org/api/http.html#http_message_headers
7const ignoreDuplicateOf = utils.toObjectSet([
8 'age',
9 'authorization',
10 'content-length',
11 'content-type',
12 'etag',
13 'expires',
14 'from',
15 'host',
16 'if-modified-since',
17 'if-unmodified-since',
18 'last-modified',
19 'location',
20 'max-forwards',
21 'proxy-authorization',
22 'referer',
23 'retry-after',
24 'user-agent',
25]);
26
27/**
28 * Parse headers into an object
29 *
30 * ```
31 * Date: Wed, 27 Aug 2014 08:58:49 GMT
32 * Content-Type: application/json
33 * Connection: keep-alive
34 * Transfer-Encoding: chunked
35 * ```
36 *
37 * @param {String} rawHeaders Headers needing to be parsed
38 *
39 * @returns {Object} Headers parsed into an object
40 */
41export default (rawHeaders) => {
42 const parsed = {};
43 let key;
44 let val;
45 let i;
46
47 rawHeaders &&
48 rawHeaders.split('\n').forEach(function parser(line) {
49 i = line.indexOf(':');
50 key = line.substring(0, i).trim().toLowerCase();
51 val = line.substring(i + 1).trim();
52
53 if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
54 return;
55 }
56
57 if (key === 'set-cookie') {
58 if (parsed[key]) {
59 parsed[key].push(val);
60 } else {
61 parsed[key] = [val];
62 }
63 } else {
64 parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
65 }
66 });
67
68 return parsed;
69};
Note: See TracBrowser for help on using the repository browser.