| 68 | namespace http { |
| 69 | |
| 70 | FetchRequest::FetchRequest(const fl::string& url, const FetchOptions& opts, fl::task::Promise<Response> prom) |
| 71 | : mState(DNS_LOOKUP) |
| 72 | , mPromise(prom) |
| 73 | , mParsedUrl(url) |
| 74 | , mHostname() |
| 75 | , mPort(80) |
| 76 | , mPath("/") |
| 77 | , mSocketFd(-1) |
| 78 | , mDnsResult(nullptr) |
| 79 | , mRequestBuffer() |
| 80 | , mResponseBuffer() |
| 81 | , mBytesSent(0) |
| 82 | , mStateStartTime(fl::millis()) |
| 83 | { |
| 84 | if (!mParsedUrl.isValid() || mParsedUrl.host().empty()) { |
| 85 | complete_error("Invalid URL"); |
| 86 | return; |
| 87 | } |
| 88 | mHostname = fl::string(mParsedUrl.host().data(), mParsedUrl.host().size()); |
| 89 | mPort = mParsedUrl.port(); |
| 90 | fl::string_view p = mParsedUrl.path(); |
| 91 | mPath = p.empty() ? fl::string("/") : fl::string(p.data(), p.size()); |
| 92 | } |
| 93 | |
| 94 | FetchRequest::~FetchRequest() FL_NOEXCEPT { |
| 95 | close_socket(); |