forked from AndreLouisCaron/httpxx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AndreLouisCaron#13 from avitebskiy/feature-dev
Added MessageBuilder, RequestBuilder, and ResponseBuilder
- Loading branch information
Showing
20 changed files
with
699 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# git-ls-files --others --exclude-from=.git/info/exclude | ||
work/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "libs/http-parser"] | ||
path = libs/http-parser | ||
url = git://github.com/AndreLouisCaron/http-parser.git | ||
url=git://github.com/joyent/http-parser.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include "MessageBuilder.hpp" | ||
|
||
#include <stdio.h> | ||
|
||
#if defined(_MSC_VER) && !defined(snprinf) | ||
#define snprintf sprintf_s | ||
#endif | ||
|
||
namespace http | ||
{ | ||
MessageBuilder::MessageBuilder() : | ||
myMajorVersion(1), myMinorVersion(0) | ||
{ | ||
|
||
} | ||
|
||
MessageBuilder::MessageBuilder(const Message& message) : | ||
myMajorVersion(1), myMinorVersion(0) | ||
{ | ||
if(message.headers_complete()) | ||
{ | ||
myMajorVersion = message.major_version(); | ||
myMinorVersion = message.minor_version(); | ||
myFlags = message.flags(); | ||
myHeaders = message.headers(); | ||
} | ||
} | ||
|
||
int MessageBuilder::major_version() const | ||
{ | ||
return myMajorVersion; | ||
} | ||
|
||
void MessageBuilder::set_major_version(int majorVersion) | ||
{ | ||
myMajorVersion = majorVersion; | ||
} | ||
|
||
int MessageBuilder::minor_version() const | ||
{ | ||
return myMinorVersion; | ||
} | ||
|
||
void MessageBuilder::set_minor_version(int minorVersion) | ||
{ | ||
myMinorVersion = minorVersion; | ||
} | ||
|
||
const Flags& MessageBuilder::flags() const | ||
{ | ||
return myFlags; | ||
} | ||
|
||
Flags& MessageBuilder::flags() | ||
{ | ||
return myFlags; | ||
} | ||
|
||
void MessageBuilder::set_flags(const Flags& flags) | ||
{ | ||
myFlags = flags; | ||
} | ||
|
||
Message::Headers& MessageBuilder::headers() | ||
{ | ||
return myHeaders; | ||
} | ||
|
||
const Message::Headers& MessageBuilder::headers() const | ||
{ | ||
return myHeaders; | ||
} | ||
|
||
std::string MessageBuilder::version_to_string() const | ||
{ | ||
std::string versionString("HTTP/"); | ||
char majorVersion[16] = {0}; | ||
char minorVersion[16] = {0}; | ||
|
||
snprintf(majorVersion, 16, "%d", major_version()); | ||
snprintf(minorVersion, 16, "%d", minor_version()); | ||
|
||
versionString += majorVersion; | ||
versionString += "."; | ||
versionString += minorVersion; | ||
|
||
return versionString; | ||
} | ||
|
||
std::string MessageBuilder::headers_to_string() const | ||
{ | ||
std::string headersString; | ||
for(Message::Headers::const_iterator cit = myHeaders.cbegin(); cit != myHeaders.cend(); ++cit) | ||
{ | ||
headersString += cit->first; | ||
headersString += ": "; | ||
headersString += cit->second; | ||
headersString += "\r\n"; | ||
} | ||
|
||
return headersString; | ||
} | ||
} |
Oops, something went wrong.