| 415 | } |
| 416 | |
| 417 | class ClientResponseImpl extends IncomingMessageImpl<HttpClientError.HttpClientError> |
| 418 | implements HttpClientResponse.HttpClientResponse, Pipeable |
| 419 | { |
| 420 | readonly [HttpClientResponse.TypeId]: typeof HttpClientResponse.TypeId |
| 421 | readonly request: HttpClientRequest.HttpClientRequest |
| 422 | private readonly requestUrl: string |
| 423 | |
| 424 | constructor( |
| 425 | request: HttpClientRequest.HttpClientRequest, |
| 426 | source: globalThis.XMLHttpRequest, |
| 427 | requestUrl: string |
| 428 | ) { |
| 429 | super(source, (cause) => |
| 430 | new HttpClientError.HttpClientError({ |
| 431 | reason: new HttpClientError.DecodeError({ |
| 432 | request, |
| 433 | response: this, |
| 434 | cause |
| 435 | }) |
| 436 | })) |
| 437 | this.request = request |
| 438 | this.requestUrl = requestUrl |
| 439 | this[HttpClientResponse.TypeId] = HttpClientResponse.TypeId |
| 440 | } |
| 441 | |
| 442 | get status() { |
| 443 | return this.source.status |
| 444 | } |
| 445 | |
| 446 | get url() { |
| 447 | return (this.source.responseURL || this.requestUrl).split("#")[0] |
| 448 | } |
| 449 | |
| 450 | get formData(): Effect.Effect<FormData, HttpClientError.HttpClientError> { |
| 451 | return Effect.flatMap(this.arrayBuffer, (body) => |
| 452 | Effect.tryPromise({ |
| 453 | try: () => new globalThis.Response(body, { headers: this.headers }).formData(), |
| 454 | catch: this.onError |
| 455 | })) |
| 456 | } |
| 457 | |
| 458 | get upgrade(): Effect.Effect<Socket.Socket, HttpClientError.HttpClientError> { |
| 459 | return Effect.fail( |
| 460 | new HttpClientError.HttpClientError({ |
| 461 | reason: new HttpClientError.StatusCodeError({ |
| 462 | request: this.request, |
| 463 | response: this, |
| 464 | description: "XMLHttpRequest cannot hand over the connection of an HTTP upgrade" |
| 465 | }) |
| 466 | }) |
| 467 | ) |
| 468 | } |
| 469 | |
| 470 | override toString(): string { |
| 471 | return `ClientResponse(${this.status})` |
| 472 | } |
| 473 | |
| 474 | toJSON(): unknown { |
nothing calls this directly
no outgoing calls
no test coverage detected