| 214 | } |
| 215 | |
| 216 | Result HttpAsyncClient::prepareRequest(const RequestPreset& preset) |
| 217 | { |
| 218 | response.reset(connection->getHeaderMemory()); |
| 219 | SC_TRY( |
| 220 | response.initBodyStream(connection->buffersPool, {[this]() -> Result { return onResponseBodyStreamRead(); }})); |
| 221 | |
| 222 | SC_TRY(currentURL.parse(preset.url)); |
| 223 | const bool isHttp = HttpStringIterator::equalsIgnoreCase(currentURL.protocol, "http"); |
| 224 | const bool isHttps = HttpStringIterator::equalsIgnoreCase(currentURL.protocol, "https"); |
| 225 | SC_TRY_MSG(isHttp or isHttps, "HttpAsyncClient only supports http and https URLs"); |
| 226 | SC_TRY_MSG(currentURL.username.isEmpty() and currentURL.password.isEmpty(), |
| 227 | "HttpAsyncClient userinfo not supported"); |
| 228 | return Result(true); |
| 229 | } |
| 230 | |
| 231 | bool HttpAsyncClient::canReuseConnectionFor(StringSpan protocol, StringSpan host, uint16_t port) const |
| 232 | { |
| 233 | return hasOpenConnection and currentPort == port and currentProtocol == protocol and currentHost == host; |
| 234 | } |
| 235 | |
| 236 | Result HttpAsyncClient::ensureConnected() |
| 237 | { |
| 238 | if (canReuseConnectionFor(currentURL.protocol, currentURL.host, currentURL.port)) |