source: trip-planner-front/node_modules/minipass-fetch/lib/response.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[6a3a178]1'use strict'
2const http = require('http')
3const { STATUS_CODES } = http
4
5const Headers = require('./headers.js')
6const Body = require('./body.js')
7const { clone, extractContentType } = Body
8
9const INTERNALS = Symbol('Response internals')
10
11class Response extends Body {
12 constructor (body = null, opts = {}) {
13 super(body, opts)
14
15 const status = opts.status || 200
16 const headers = new Headers(opts.headers)
17
18 if (body !== null && body !== undefined && !headers.has('Content-Type')) {
19 const contentType = extractContentType(body)
20 if (contentType)
21 headers.append('Content-Type', contentType)
22 }
23
24 this[INTERNALS] = {
25 url: opts.url,
26 status,
27 statusText: opts.statusText || STATUS_CODES[status],
28 headers,
29 counter: opts.counter,
30 trailer: Promise.resolve(opts.trailer || new Headers()),
31 }
32 }
33
34 get trailer () {
35 return this[INTERNALS].trailer
36 }
37
38 get url () {
39 return this[INTERNALS].url || ''
40 }
41
42 get status () {
43 return this[INTERNALS].status
44 }
45
46 get ok () {
47 return this[INTERNALS].status >= 200 && this[INTERNALS].status < 300
48 }
49
50 get redirected () {
51 return this[INTERNALS].counter > 0
52 }
53
54 get statusText () {
55 return this[INTERNALS].statusText
56 }
57
58 get headers () {
59 return this[INTERNALS].headers
60 }
61
62 clone () {
63 return new Response(clone(this), {
64 url: this.url,
65 status: this.status,
66 statusText: this.statusText,
67 headers: this.headers,
68 ok: this.ok,
69 redirected: this.redirected,
70 trailer: this.trailer,
71 })
72 }
73
74 get [Symbol.toStringTag] () {
75 return 'Response'
76 }
77}
78
79module.exports = Response
80
81Object.defineProperties(Response.prototype, {
82 url: { enumerable: true },
83 status: { enumerable: true },
84 ok: { enumerable: true },
85 redirected: { enumerable: true },
86 statusText: { enumerable: true },
87 headers: { enumerable: true },
88 clone: { enumerable: true },
89})
Note: See TracBrowser for help on using the repository browser.