| 293 | let encoder: TextEncoder | undefined |
| 294 | |
| 295 | class Response extends Inspectable.Class implements HttpClientResponse.HttpClientResponse { |
| 296 | readonly [HttpIncomingMessage.TypeId]: typeof HttpIncomingMessage.TypeId = HttpIncomingMessage.TypeId |
| 297 | readonly [HttpClientResponse.TypeId]: typeof HttpClientResponse.TypeId = HttpClientResponse.TypeId |
| 298 | readonly cookies: Cookies.Cookies = Cookies.empty |
| 299 | readonly remoteAddress: Option.Option<string> = Option.none() |
| 300 | readonly request: HttpClientRequest.HttpClientRequest |
| 301 | readonly status: number |
| 302 | readonly headers: Headers.Headers |
| 303 | readonly url: string |
| 304 | private readonly exchange: Exchange |
| 305 | private readonly binary: boolean |
| 306 | private streamed = false |
| 307 | |
| 308 | constructor( |
| 309 | request: HttpClientRequest.HttpClientRequest, |
| 310 | status: number, |
| 311 | headers: Headers.Headers, |
| 312 | url: string, |
| 313 | exchange: Exchange, |
| 314 | binary: boolean |
| 315 | ) { |
| 316 | super() |
| 317 | this.request = request |
| 318 | this.status = status |
| 319 | this.headers = headers |
| 320 | this.url = url |
| 321 | this.exchange = exchange |
| 322 | this.binary = binary |
| 323 | } |
| 324 | |
| 325 | private decodeError( |
| 326 | description: string, |
| 327 | cause?: unknown |
| 328 | ): HttpClientError.HttpClientError { |
| 329 | return new HttpClientError.HttpClientError({ |
| 330 | reason: new HttpClientError.DecodeError({ |
| 331 | request: this.request, |
| 332 | response: this, |
| 333 | description, |
| 334 | cause |
| 335 | }) |
| 336 | }) |
| 337 | } |
| 338 | |
| 339 | private failed(error: string): HttpClientError.HttpClientError { |
| 340 | return this.decodeError(`The response failed: ${error}`, error) |
| 341 | } |
| 342 | |
| 343 | private unreadable(): HttpClientError.HttpClientError | undefined { |
| 344 | const type = this.headers["content-type"] |
| 345 | if (!this.binary && type !== undefined && binaryType.test(type)) { |
| 346 | return this.decodeError( |
| 347 | `A ${type} body can't be read as text: set NativeHttpClient.ResponseType to "binary"` |
| 348 | ) |
| 349 | } |
| 350 | if (this.streamed) { |
| 351 | return this.decodeError("The body was already read as a stream") |
| 352 | } |
nothing calls this directly
no outgoing calls
no test coverage detected