Unverified Commit d8ae8ddf authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Revert "Use a std::shared_ptr<std::string> instead of std::string for the...

Revert "Use a std::shared_ptr<std::string> instead of std::string for the body_ member variable in Pistache::Http::Message (#814)" (#816)

This reverts commit a09290ee.
parent a09290ee
...@@ -71,14 +71,14 @@ public: ...@@ -71,14 +71,14 @@ public:
friend class Private::BodyStep; friend class Private::BodyStep;
friend class ResponseWriter; friend class ResponseWriter;
Message(); Message() = default;
explicit Message(Version version); explicit Message(Version version);
Message(const Message &other) = default; Message(const Message &other) = default;
Message &operator=(const Message &other) = default; Message &operator=(const Message &other) = default;
Message(Message &&other); Message(Message &&other) = default;
Message &operator=(Message &&other); Message &operator=(Message &&other) = default;
Version version() const; Version version() const;
Code code() const; Code code() const;
...@@ -91,10 +91,10 @@ public: ...@@ -91,10 +91,10 @@ public:
Header::Collection &headers(); Header::Collection &headers();
protected: protected:
Version version_; Version version_ = Version::Http11;
Code code_; Code code_;
std::shared_ptr<std::string> body_; std::string body_;
CookieJar cookies_; CookieJar cookies_;
Header::Collection headers_; Header::Collection headers_;
......
...@@ -743,12 +743,12 @@ RequestBuilder &RequestBuilder::cookie(const Cookie &cookie) { ...@@ -743,12 +743,12 @@ RequestBuilder &RequestBuilder::cookie(const Cookie &cookie) {
} }
RequestBuilder &RequestBuilder::body(const std::string &val) { RequestBuilder &RequestBuilder::body(const std::string &val) {
*(request_.body_) = val; request_.body_ = val;
return *this; return *this;
} }
RequestBuilder &RequestBuilder::body(std::string &&val) { RequestBuilder &RequestBuilder::body(std::string &&val) {
*(request_.body_) = std::move(val); request_.body_ = std::move(val);
return *this; return *this;
} }
......
...@@ -360,7 +360,7 @@ State BodyStep::parseContentLength( ...@@ -360,7 +360,7 @@ State BodyStep::parseContentLength(
// We have an incomplete body, read what we can // We have an incomplete body, read what we can
if (available < size) { if (available < size) {
cursor.advance(available); cursor.advance(available);
message->body_->append(token.rawText(), token.size()); message->body_.append(token.rawText(), token.size());
bytesRead += available; bytesRead += available;
...@@ -368,7 +368,7 @@ State BodyStep::parseContentLength( ...@@ -368,7 +368,7 @@ State BodyStep::parseContentLength(
} }
cursor.advance(size); cursor.advance(size);
message->body_->append(token.rawText(), token.size()); message->body_.append(token.rawText(), token.size());
return true; return true;
}; };
...@@ -381,7 +381,7 @@ State BodyStep::parseContentLength( ...@@ -381,7 +381,7 @@ State BodyStep::parseContentLength(
} }
// This is the first time we are reading the payload // This is the first time we are reading the payload
else { else {
message->body_->reserve(contentLength); message->body_.reserve(contentLength);
if (!readBody(contentLength)) if (!readBody(contentLength))
return State::Again; return State::Again;
} }
...@@ -417,21 +417,21 @@ BodyStep::Chunk::Result BodyStep::Chunk::parse(StreamCursor &cursor) { ...@@ -417,21 +417,21 @@ BodyStep::Chunk::Result BodyStep::Chunk::parse(StreamCursor &cursor) {
if (size == 0) if (size == 0)
return Final; return Final;
message->body_->reserve(size); message->body_.reserve(size);
StreamCursor::Token chunkData(cursor); StreamCursor::Token chunkData(cursor);
const ssize_t available = cursor.remaining(); const ssize_t available = cursor.remaining();
if (static_cast<ssize_t>(available + message->body_->size()) < size) { if (static_cast<ssize_t>(available + message->body_.size()) < size) {
cursor.advance(available); cursor.advance(available);
message->body_->append(chunkData.rawText(), available); message->body_.append(chunkData.rawText(), available);
return Incomplete; return Incomplete;
} }
cursor.advance(size - message->body_->size()); cursor.advance(size - message->body_.size());
if (!cursor.advance(2)) if (!cursor.advance(2))
return Incomplete; return Incomplete;
message->body_->append(chunkData.rawText(), size - message->body_->size()); message->body_.append(chunkData.rawText(), size - message->body_.size());
return Complete; return Complete;
} }
...@@ -531,35 +531,13 @@ bool Query::has(const std::string &name) const { ...@@ -531,35 +531,13 @@ bool Query::has(const std::string &name) const {
} // namespace Uri } // namespace Uri
Message::Message() : Message(Version::Http11) {} Message::Message(Version version) : version_(version) {}
Message::Message(Version version)
: version_(version), body_(std::make_shared<std::string>()) {}
Message::Message(Message &&other)
: version_(std::move(other.version_)), code_(std::move(other.code_)),
body_(std::move(other.body_)), cookies_(std::move(other.cookies_)),
headers_(std::move(other.headers_)) {
other.body_ = std::make_shared<std::string>();
}
Message &Message::operator=(Message &&other) {
version_ = std::move(other.version_);
code_ = std::move(other.code_);
body_ = std::move(other.body_);
cookies_ = std::move(other.cookies_);
headers_ = std::move(other.headers_);
other.body_ = std::make_shared<std::string>();
return *this;
}
Version Message::version() const { return version_; } Version Message::version() const { return version_; }
Code Message::code() const { return code_; } Code Message::code() const { return code_; }
std::string Message::body() const { return *body_; } std::string Message::body() const { return body_; }
const Header::Collection &Message::headers() const { return headers_; } const Header::Collection &Message::headers() const { return headers_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment