Skip to content

Commit

Permalink
🩹 fix: fix issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
maro5397 committed Dec 16, 2021
1 parent 05b2a6d commit 5dd867c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ typedef enum {HTTP1_0, HTTP1_1, HTTP_UNSUPPORTED} Protocol;

#include <string>
#include <vector>
#include <glog/logging.h>
16 changes: 11 additions & 5 deletions src/httprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ int HTTPRequest::parseRequestPacket()
int HTTPRequest::makeRequest()
{
string httpmethod, httpprotocol;
string tmppacket = "";

switch(method_){
case GET:
Expand Down Expand Up @@ -221,13 +222,13 @@ int HTTPRequest::makeRequest()
break;
}

requestpacket_ += httpmethod + " " + url_ + " " + httpprotocol + CRLF;
tmppacket += httpmethod + " " + url_ + " " + httpprotocol + CRLF;
vector<pair<string, string>>::iterator iter;
for(iter = headers_.begin(); iter != headers_.end(); iter++){
requestpacket_ += (*iter).first + ": " + (*iter).second + CRLF;
tmppacket += (*iter).first + ": " + (*iter).second + CRLF;
}
requestpacket_ += CRLF;
requestpacket_ += body_;
tmppacket += CRLF + body_;
requestpacket_ = tmppacket;
return 0;
}

Expand All @@ -243,8 +244,13 @@ string* HTTPRequest::getRequestData()

string HTTPRequest::updateCursor(size_t& cursorbegin, size_t& cursorend, string target, string obj, size_t next)
{
string result;
string result = "";
size_t tmp = cursorend;
cursorend = obj.find_first_of(target, cursorbegin);
if(cursorend == string::npos) {
cursorend = tmp;
return result;
}
result = obj.substr(cursorbegin, cursorend - cursorbegin);
cursorbegin = cursorend + next;
return result;
Expand Down
12 changes: 9 additions & 3 deletions src/httpresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ string HTTPResponse::getResponseBody()
int HTTPResponse::makeResponse()
{
string httpprotocol;
string tmppacket;
string tmppacket = "";

switch(protocol_){
case HTTP1_0:
Expand Down Expand Up @@ -231,8 +231,13 @@ string* HTTPResponse::getResponseData()

string HTTPResponse::updateCursor(size_t& cursorbegin, size_t& cursorend, string target, string obj, size_t next)
{
string result;
string result = "";
size_t tmp = cursorend;
cursorend = obj.find_first_of(target, cursorbegin);
if(cursorend == string::npos) {
cursorend = tmp;
return result;
}
result = obj.substr(cursorbegin, cursorend - cursorbegin);
cursorbegin = cursorend + next;
return result;
Expand All @@ -241,5 +246,6 @@ string HTTPResponse::updateCursor(size_t& cursorbegin, size_t& cursorend, string
void HTTPResponse::resetData()
{
responsepacket_ = "";
DLOG(INFO) << "response header size:" << headers_.size();
headers_.clear();
}
}

0 comments on commit 5dd867c

Please sign in to comment.