11cb0ef41Sopenharmony_ci'use strict'
21cb0ef41Sopenharmony_ciconst http = require('http')
31cb0ef41Sopenharmony_ciconst { STATUS_CODES } = http
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst Headers = require('./headers.js')
61cb0ef41Sopenharmony_ciconst Body = require('./body.js')
71cb0ef41Sopenharmony_ciconst { clone, extractContentType } = Body
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst INTERNALS = Symbol('Response internals')
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciclass Response extends Body {
121cb0ef41Sopenharmony_ci  constructor (body = null, opts = {}) {
131cb0ef41Sopenharmony_ci    super(body, opts)
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci    const status = opts.status || 200
161cb0ef41Sopenharmony_ci    const headers = new Headers(opts.headers)
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci    if (body !== null && body !== undefined && !headers.has('Content-Type')) {
191cb0ef41Sopenharmony_ci      const contentType = extractContentType(body)
201cb0ef41Sopenharmony_ci      if (contentType) {
211cb0ef41Sopenharmony_ci        headers.append('Content-Type', contentType)
221cb0ef41Sopenharmony_ci      }
231cb0ef41Sopenharmony_ci    }
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci    this[INTERNALS] = {
261cb0ef41Sopenharmony_ci      url: opts.url,
271cb0ef41Sopenharmony_ci      status,
281cb0ef41Sopenharmony_ci      statusText: opts.statusText || STATUS_CODES[status],
291cb0ef41Sopenharmony_ci      headers,
301cb0ef41Sopenharmony_ci      counter: opts.counter,
311cb0ef41Sopenharmony_ci      trailer: Promise.resolve(opts.trailer || new Headers()),
321cb0ef41Sopenharmony_ci    }
331cb0ef41Sopenharmony_ci  }
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  get trailer () {
361cb0ef41Sopenharmony_ci    return this[INTERNALS].trailer
371cb0ef41Sopenharmony_ci  }
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  get url () {
401cb0ef41Sopenharmony_ci    return this[INTERNALS].url || ''
411cb0ef41Sopenharmony_ci  }
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  get status () {
441cb0ef41Sopenharmony_ci    return this[INTERNALS].status
451cb0ef41Sopenharmony_ci  }
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  get ok () {
481cb0ef41Sopenharmony_ci    return this[INTERNALS].status >= 200 && this[INTERNALS].status < 300
491cb0ef41Sopenharmony_ci  }
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  get redirected () {
521cb0ef41Sopenharmony_ci    return this[INTERNALS].counter > 0
531cb0ef41Sopenharmony_ci  }
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  get statusText () {
561cb0ef41Sopenharmony_ci    return this[INTERNALS].statusText
571cb0ef41Sopenharmony_ci  }
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  get headers () {
601cb0ef41Sopenharmony_ci    return this[INTERNALS].headers
611cb0ef41Sopenharmony_ci  }
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci  clone () {
641cb0ef41Sopenharmony_ci    return new Response(clone(this), {
651cb0ef41Sopenharmony_ci      url: this.url,
661cb0ef41Sopenharmony_ci      status: this.status,
671cb0ef41Sopenharmony_ci      statusText: this.statusText,
681cb0ef41Sopenharmony_ci      headers: this.headers,
691cb0ef41Sopenharmony_ci      ok: this.ok,
701cb0ef41Sopenharmony_ci      redirected: this.redirected,
711cb0ef41Sopenharmony_ci      trailer: this.trailer,
721cb0ef41Sopenharmony_ci    })
731cb0ef41Sopenharmony_ci  }
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci  get [Symbol.toStringTag] () {
761cb0ef41Sopenharmony_ci    return 'Response'
771cb0ef41Sopenharmony_ci  }
781cb0ef41Sopenharmony_ci}
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_cimodule.exports = Response
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_ciObject.defineProperties(Response.prototype, {
831cb0ef41Sopenharmony_ci  url: { enumerable: true },
841cb0ef41Sopenharmony_ci  status: { enumerable: true },
851cb0ef41Sopenharmony_ci  ok: { enumerable: true },
861cb0ef41Sopenharmony_ci  redirected: { enumerable: true },
871cb0ef41Sopenharmony_ci  statusText: { enumerable: true },
881cb0ef41Sopenharmony_ci  headers: { enumerable: true },
891cb0ef41Sopenharmony_ci  clone: { enumerable: true },
901cb0ef41Sopenharmony_ci})
91