| 121 | } // namespace |
| 122 | |
| 123 | bool HttpRequestCommand::executeInternal() |
| 124 | { |
| 125 | // socket->setBlockingMode(); |
| 126 | if (httpConnection_->sendBufferIsEmpty()) { |
| 127 | #ifdef ENABLE_SSL |
| 128 | if (getRequest()->getProtocol() == "https") { |
| 129 | if (!getSocket()->tlsConnect(getRequest()->getHost())) { |
| 130 | setReadCheckSocketIf(getSocket(), getSocket()->wantRead()); |
| 131 | setWriteCheckSocketIf(getSocket(), getSocket()->wantWrite()); |
| 132 | addCommandSelf(); |
| 133 | return false; |
| 134 | } |
| 135 | } |
| 136 | #endif // ENABLE_SSL |
| 137 | if (getSegments().empty()) { |
| 138 | auto httpRequest = createHttpRequest( |
| 139 | getRequest(), getFileEntry(), std::shared_ptr<Segment>(), getOption(), |
| 140 | getRequestGroup(), getDownloadEngine(), proxyRequest_); |
| 141 | if (getOption()->getAsBool(PREF_CONDITIONAL_GET) && |
| 142 | (getRequest()->getProtocol() == "http" || |
| 143 | getRequest()->getProtocol() == "https")) { |
| 144 | |
| 145 | std::string path; |
| 146 | |
| 147 | if (getFileEntry()->getPath().empty()) { |
| 148 | auto& file = getRequest()->getFile(); |
| 149 | |
| 150 | // If filename part of URI is empty, we just use |
| 151 | // Request::DEFAULT_FILE, since it is the name we use to |
| 152 | // store file in disk. |
| 153 | |
| 154 | path = util::createSafePath( |
| 155 | getOption()->get(PREF_DIR), |
| 156 | (getRequest()->getFile().empty() |
| 157 | ? Request::DEFAULT_FILE |
| 158 | : util::percentDecode(std::begin(file), std::end(file)))); |
| 159 | } |
| 160 | else { |
| 161 | path = getFileEntry()->getPath(); |
| 162 | } |
| 163 | |
| 164 | File ctrlfile(path + DefaultBtProgressInfoFile::getSuffix()); |
| 165 | File file(path); |
| 166 | |
| 167 | if (!ctrlfile.exists() && file.exists()) { |
| 168 | httpRequest->setIfModifiedSinceHeader( |
| 169 | file.getModifiedTime().toHTTPDate()); |
| 170 | } |
| 171 | } |
| 172 | httpConnection_->sendRequest(std::move(httpRequest)); |
| 173 | } |
| 174 | else { |
| 175 | for (auto& segment : getSegments()) { |
| 176 | if (!httpConnection_->isIssued(segment)) { |
| 177 | int64_t endOffset = 0; |
| 178 | // FTP via HTTP proxy does not support end byte marker |
| 179 | if (getRequest()->getProtocol() != "ftp" && |
| 180 | getRequestGroup()->getTotalLength() > 0 && getPieceStorage()) { |
nothing calls this directly
no test coverage detected