* Send this request with a optional body. * * Note: if you dont consume the response body you should call `Response.body.close()` * (this is done automatically after 30 seconds if you don't, but if you're sending a lot of requests its better to do it yourself) *
(body?: RequestBody)
| 159 | * @returns A promise that resolbes with the response |
| 160 | */ |
| 161 | async send(body?: RequestBody): Promise<Response> { |
| 162 | let reqBodyRid: number | undefined = undefined; |
| 163 | if (body) { |
| 164 | this.headers = this.headers ?? {} |
| 165 | body.setHeaders(this.headers); |
| 166 | |
| 167 | let [senderRid, receiverRid] = OpWrappers.http.createRequestStream(); |
| 168 | this.writeBody(body, senderRid).finally(() => Deno.core.tryClose(senderRid)); |
| 169 | reqBodyRid = receiverRid |
| 170 | } |
| 171 | |
| 172 | let resp = await OpWrappers.http.requestSend({ |
| 173 | headers: this.headers ?? {}, |
| 174 | method: this.method, |
| 175 | path: this.path, |
| 176 | scriptId: this.scriptId ?? 0, |
| 177 | bodyResourceId: reqBodyRid, |
| 178 | }); |
| 179 | |
| 180 | let respBody = new NativeReader(resp.bodyResourceId); |
| 181 | |
| 182 | return new Response(resp.statusCode, resp.headers, respBody); |
| 183 | } |
| 184 | |
| 185 | then(okay: (val: Response) => any, rejected: (err: any) => unknown) { |
| 186 | return this.send().then(okay).catch(rejected); |
no test coverage detected