diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-06-08 13:12:24 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-06-08 13:12:24 +0000 |
| commit | 8de7cff9f41aa4778619a426f1983e68bdcea1bb (patch) | |
| tree | 3c9aadde1c96f0c08fcdb1214dcec0a95e96cfca /src/HttpHeaderProcessor.cc | |
| parent | cf71523fe27f37146d19606f10eb8348b20629d9 (diff) | |
2008-06-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/HttpHeaderProcessor.cc: Rewritten using std::string as a
buffer.
* src/HttpHeaderProcessor.h: Rewritten using std::string as a
buffer.
* src/HttpConnection.cc: Included missing sstream.
Diffstat (limited to 'src/HttpHeaderProcessor.cc')
| -rw-r--r-- | src/HttpHeaderProcessor.cc | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/src/HttpHeaderProcessor.cc b/src/HttpHeaderProcessor.cc index bf35d697..9b2ef0e0 100644 --- a/src/HttpHeaderProcessor.cc +++ b/src/HttpHeaderProcessor.cc @@ -39,6 +39,7 @@ #include "DlRetryEx.h" #include "DlAbortEx.h" #include "A2STR.h" +#include <sstream> namespace aria2 { @@ -49,28 +50,26 @@ HttpHeaderProcessor::~HttpHeaderProcessor() {} void HttpHeaderProcessor::update(const unsigned char* data, size_t length) { checkHeaderLimit(length); - strm.write(reinterpret_cast<const char*>(data), length); + _buf += std::string(&data[0], &data[length]); } void HttpHeaderProcessor::update(const std::string& data) { checkHeaderLimit(data.size()); - strm << data; + _buf += data; } void HttpHeaderProcessor::checkHeaderLimit(size_t incomingLength) { - strm.seekg(0, std::ios::end); - if((size_t)strm.tellg()+incomingLength > _limit) { + if(_buf.size()+incomingLength > _limit) { throw DlAbortEx("Too large http header"); } - strm.clear(); } bool HttpHeaderProcessor::eoh() const { - std::string str = strm.str(); - if(str.find("\r\n\r\n") == std::string::npos && str.find("\n\n") == std::string::npos) { + if(_buf.find("\r\n\r\n") == std::string::npos && + _buf.find("\n\n") == std::string::npos) { return false; } else { return true; @@ -79,12 +78,11 @@ bool HttpHeaderProcessor::eoh() const size_t HttpHeaderProcessor::getPutBackDataLength() const { - const std::string& str = strm.str(); std::string::size_type delimpos = std::string::npos; - if((delimpos = str.find("\r\n\r\n")) != std::string::npos) { - return str.size()-(delimpos+4); - } else if((delimpos = str.find("\n\n")) != std::string::npos) { - return str.size()-(delimpos+2); + if((delimpos = _buf.find("\r\n\r\n")) != std::string::npos) { + return _buf.size()-(delimpos+4); + } else if((delimpos = _buf.find("\n\n")) != std::string::npos) { + return _buf.size()-(delimpos+2); } else { return 0; } @@ -92,35 +90,35 @@ size_t HttpHeaderProcessor::getPutBackDataLength() const void HttpHeaderProcessor::clear() { - strm.str(A2STR::NIL); + _buf.erase(); } SharedHandle<HttpHeader> HttpHeaderProcessor::getHttpResponseHeader() { - strm.seekg(0, std::ios::beg); - std::string line; - getline(strm, line); - // check HTTP status value - if(line.size() <= 12) { + std::string::size_type delimpos = std::string::npos; + if(((delimpos = _buf.find("\r\n")) == std::string::npos && + (delimpos = _buf.find("\n")) == std::string::npos) || + delimpos < 12) { throw DlRetryEx(EX_NO_STATUS_HEADER); } HttpHeaderHandle httpHeader(new HttpHeader()); - httpHeader->setResponseStatus(line.substr(9, 3)); - httpHeader->setVersion(line.substr(0, 8)); + httpHeader->setVersion(_buf.substr(0, 8)); + httpHeader->setResponseStatus(_buf.substr(9, 3)); + std::istringstream strm(_buf); + // TODO 1st line(HTTP/1.1 200...) is also send to HttpHeader, but it should + // not. httpHeader->fill(strm); - strm.clear(); return httpHeader; } std::string HttpHeaderProcessor::getHeaderString() const { - std::string str = strm.str(); std::string::size_type delimpos = std::string::npos; - if((delimpos = str.find("\r\n\r\n")) != std::string::npos || - (delimpos = str.find("\n\n")) != std::string::npos) { - return str.substr(0, delimpos); + if((delimpos = _buf.find("\r\n\r\n")) == std::string::npos && + (delimpos = _buf.find("\n\n")) == std::string::npos) { + return _buf; } else { - return str; + return _buf.substr(0, delimpos); } } |
