diff options
Diffstat (limited to 'src/HttpRequest.cc')
| -rw-r--r-- | src/HttpRequest.cc | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index c2400550..4fa090aa 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -55,40 +55,40 @@ namespace aria2 { const std::string HttpRequest::USER_AGENT("aria2"); -HttpRequest::HttpRequest():_contentEncodingEnabled(true), - _userAgent(USER_AGENT), - _noCache(true), - _acceptGzip(false) +HttpRequest::HttpRequest():contentEncodingEnabled_(true), + userAgent_(USER_AGENT), + noCache_(true), + acceptGzip_(false) {} void HttpRequest::setSegment(const SharedHandle<Segment>& segment) { - _segment = segment; + segment_ = segment; } void HttpRequest::setRequest(const SharedHandle<Request>& request) { - _request = request; + request_ = request; } off_t HttpRequest::getStartByte() const { - if(_segment.isNull()) { + if(segment_.isNull()) { return 0; } else { - return _fileEntry->gtoloff(_segment->getPositionToWrite()); + return fileEntry_->gtoloff(segment_->getPositionToWrite()); } } off_t HttpRequest::getEndByte() const { - if(_segment.isNull() || _request.isNull()) { + if(segment_.isNull() || request_.isNull()) { return 0; } else { - if(_request->isPipeliningEnabled()) { + if(request_->isPipeliningEnabled()) { off_t endByte = - _fileEntry->gtoloff(_segment->getPosition()+_segment->getLength()-1); - return std::min(endByte, static_cast<off_t>(_fileEntry->getLength()-1)); + fileEntry_->gtoloff(segment_->getPosition()+segment_->getLength()-1); + return std::min(endByte, static_cast<off_t>(fileEntry_->getLength()-1)); } else { return 0; } @@ -98,24 +98,24 @@ off_t HttpRequest::getEndByte() const RangeHandle HttpRequest::getRange() const { // content-length is always 0 - if(_segment.isNull()) { + if(segment_.isNull()) { return SharedHandle<Range>(new Range()); } else { return SharedHandle<Range>(new Range(getStartByte(), getEndByte(), - _fileEntry->getLength())); + fileEntry_->getLength())); } } bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const { - if(_segment.isNull()) { + if(segment_.isNull()) { return true; } if((getStartByte() == range->getStartByte()) && ((getEndByte() == 0) || (getEndByte() == range->getEndByte())) && - ((_fileEntry->getLength() == 0) || - (_fileEntry->getLength() == range->getEntityLength()))) { + ((fileEntry_->getLength() == 0) || + (fileEntry_->getLength() == range->getEntityLength()))) { return true; } else { return false; @@ -133,16 +133,16 @@ static std::string getHostText(const std::string& host, uint16_t port) std::string HttpRequest::createRequest() { - _authConfig = _authConfigFactory->createAuthConfig(_request, _option); - std::string requestLine = _request->getMethod(); + authConfig_ = authConfigFactory_->createAuthConfig(request_, option_); + std::string requestLine = request_->getMethod(); requestLine += " "; - if(!_proxyRequest.isNull()) { + if(!proxyRequest_.isNull()) { if(getProtocol() == Request::PROTO_FTP && - _request->getUsername().empty() && !_authConfig.isNull()) { + request_->getUsername().empty() && !authConfig_.isNull()) { // Insert user into URI, like ftp://USER@host/ std::string uri = getCurrentURI(); assert(uri.size() >= 6); - uri.insert(6, util::percentEncode(_authConfig->getUser())+"@"); + uri.insert(6, util::percentEncode(authConfig_->getUser())+"@"); requestLine += uri; } else { requestLine += getCurrentURI(); @@ -161,17 +161,17 @@ std::string HttpRequest::createRequest() std::vector<std::pair<std::string, std::string> > builtinHds; builtinHds.reserve(20); - builtinHds.push_back(std::make_pair("User-Agent:", _userAgent)); + builtinHds.push_back(std::make_pair("User-Agent:", userAgent_)); std::string acceptTypes = "*/*"; - for(std::vector<std::string>::const_iterator i = _acceptTypes.begin(), - eoi = _acceptTypes.end(); i != eoi; ++i) { + for(std::vector<std::string>::const_iterator i = acceptTypes_.begin(), + eoi = acceptTypes_.end(); i != eoi; ++i) { strappend(acceptTypes, ",", (*i)); } builtinHds.push_back(std::make_pair("Accept:", acceptTypes)); - if(_contentEncodingEnabled) { + if(contentEncodingEnabled_) { std::string acceptableEncodings; #ifdef HAVE_LIBZ - if(_acceptGzip) { + if(acceptGzip_) { acceptableEncodings += "deflate, gzip"; } #endif // HAVE_LIBZ @@ -182,46 +182,46 @@ std::string HttpRequest::createRequest() } builtinHds.push_back (std::make_pair("Host:", getHostText(getURIHost(), getPort()))); - if(_noCache) { + if(noCache_) { builtinHds.push_back(std::make_pair("Pragma:", "no-cache")); builtinHds.push_back(std::make_pair("Cache-Control:", "no-cache")); } - if(!_request->isKeepAliveEnabled() && !_request->isPipeliningEnabled()) { + if(!request_->isKeepAliveEnabled() && !request_->isPipeliningEnabled()) { builtinHds.push_back(std::make_pair("Connection:", "close")); } - if(!_segment.isNull() && _segment->getLength() > 0 && - (_request->isPipeliningEnabled() || getStartByte() > 0)) { + if(!segment_.isNull() && segment_->getLength() > 0 && + (request_->isPipeliningEnabled() || getStartByte() > 0)) { std::string rangeHeader = "bytes="; rangeHeader += util::itos(getStartByte()); rangeHeader += "-"; - if(_request->isPipeliningEnabled()) { + if(request_->isPipeliningEnabled()) { rangeHeader += util::itos(getEndByte()); } builtinHds.push_back(std::make_pair("Range:", rangeHeader)); } - if(!_proxyRequest.isNull()) { - if(_request->isKeepAliveEnabled() || _request->isPipeliningEnabled()) { + if(!proxyRequest_.isNull()) { + if(request_->isKeepAliveEnabled() || request_->isPipeliningEnabled()) { builtinHds.push_back(std::make_pair("Proxy-Connection:", "Keep-Alive")); } else { builtinHds.push_back(std::make_pair("Proxy-Connection:", "close")); } } - if(!_proxyRequest.isNull() && !_proxyRequest->getUsername().empty()) { + if(!proxyRequest_.isNull() && !proxyRequest_->getUsername().empty()) { builtinHds.push_back(getProxyAuthString()); } - if(!_authConfig.isNull()) { + if(!authConfig_.isNull()) { builtinHds.push_back (std::make_pair("Authorization:", strconcat("Basic ", - Base64::encode(_authConfig->getAuthText())))); + Base64::encode(authConfig_->getAuthText())))); } if(getPreviousURI().size()) { builtinHds.push_back(std::make_pair("Referer:", getPreviousURI())); } - if(!_cookieStorage.isNull()) { + if(!cookieStorage_.isNull()) { std::string cookiesValue; std::vector<Cookie> cookies = - _cookieStorage->criteriaFind(getHost(), + cookieStorage_->criteriaFind(getHost(), getDir(), Time().getTime(), getProtocol() == Request::PROTO_HTTPS ? @@ -236,8 +236,8 @@ std::string HttpRequest::createRequest() } for(std::vector<std::pair<std::string, std::string> >::const_iterator i = builtinHds.begin(), eoi = builtinHds.end(); i != eoi; ++i) { - std::vector<std::string>::const_iterator j = _headers.begin(); - std::vector<std::string>::const_iterator jend = _headers.end(); + std::vector<std::string>::const_iterator j = headers_.begin(); + std::vector<std::string>::const_iterator jend = headers_.end(); for(; j != jend; ++j) { if(util::startsWith(*j, (*i).first)) { break; @@ -248,8 +248,8 @@ std::string HttpRequest::createRequest() } } // append additional headers given by user. - for(std::vector<std::string>::const_iterator i = _headers.begin(), - eoi = _headers.end(); i != eoi; ++i) { + for(std::vector<std::string>::const_iterator i = headers_.begin(), + eoi = headers_.end(); i != eoi; ++i) { strappend(requestLine, (*i), A2STR::CRLF); } requestLine += A2STR::CRLF; @@ -258,13 +258,13 @@ std::string HttpRequest::createRequest() std::string HttpRequest::createProxyRequest() const { - assert(!_proxyRequest.isNull()); + assert(!proxyRequest_.isNull()); std::string hostport = getURIHost(); strappend(hostport, ":", util::uitos(getPort())); std::string requestLine = "CONNECT "; strappend(requestLine, hostport, " HTTP/1.1\r\n"); - strappend(requestLine, "User-Agent: ", _userAgent, "\r\n"); + strappend(requestLine, "User-Agent: ", userAgent_, "\r\n"); strappend(requestLine, "Host: ", hostport, "\r\n"); // TODO Is "Proxy-Connection" needed here? // if(request->isKeepAliveEnabled() || request->isPipeliningEnabled()) { @@ -272,7 +272,7 @@ std::string HttpRequest::createProxyRequest() const // }else { // requestLine += "Proxy-Connection: close\r\n"; // } - if(!_proxyRequest->getUsername().empty()) { + if(!proxyRequest_->getUsername().empty()) { std::pair<std::string, std::string> auth = getProxyAuthString(); strappend(requestLine, auth.first, " ", auth.second, A2STR::CRLF); } @@ -285,64 +285,64 @@ std::pair<std::string, std::string> HttpRequest::getProxyAuthString() const return std::make_pair ("Proxy-Authorization:", strconcat("Basic ", - Base64::encode(strconcat(_proxyRequest->getUsername(), + Base64::encode(strconcat(proxyRequest_->getUsername(), ":", - _proxyRequest->getPassword())))); + proxyRequest_->getPassword())))); } void HttpRequest::enableContentEncoding() { - _contentEncodingEnabled = true; + contentEncodingEnabled_ = true; } void HttpRequest::disableContentEncoding() { - _contentEncodingEnabled = false; + contentEncodingEnabled_ = false; } void HttpRequest::addHeader(const std::string& headersString) { std::vector<std::string> headers; util::split(headersString, std::back_inserter(headers), "\n", true); - _headers.insert(_headers.end(), headers.begin(), headers.end()); + headers_.insert(headers_.end(), headers.begin(), headers.end()); } void HttpRequest::addAcceptType(const std::string& type) { - _acceptTypes.push_back(type); + acceptTypes_.push_back(type); } void HttpRequest::setCookieStorage (const SharedHandle<CookieStorage>& cookieStorage) { - _cookieStorage = cookieStorage; + cookieStorage_ = cookieStorage; } void HttpRequest::setAuthConfigFactory (const SharedHandle<AuthConfigFactory>& factory, const Option* option) { - _authConfigFactory = factory; - _option = option; + authConfigFactory_ = factory; + option_ = option; } void HttpRequest::setProxyRequest(const SharedHandle<Request>& proxyRequest) { - _proxyRequest = proxyRequest; + proxyRequest_ = proxyRequest; } bool HttpRequest::isProxyRequestSet() const { - return !_proxyRequest.isNull(); + return !proxyRequest_.isNull(); } bool HttpRequest::authenticationUsed() const { - return !_authConfig.isNull(); + return !authConfig_.isNull(); } const SharedHandle<AuthConfig>& HttpRequest::getAuthConfig() const { - return _authConfig; + return authConfig_; } } // namespace aria2 |
