-
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 #97 from smatsuodev/refactor-request-reader
RequestReader を state pattern で refactor
- Loading branch information
Showing
17 changed files
with
681 additions
and
334 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
#include "reading_body_state.hpp" | ||
#include "core/virtual_server.hpp" | ||
#include "utils/logger.hpp" | ||
#include "utils/types/try.hpp" | ||
|
||
http::ReadingBodyState::ReadingBodyState(RequestReader &reader, const std::size_t contentLength) | ||
: reader_(reader), contentLength_(contentLength) {} | ||
|
||
Result<http::RequestReader::IState::HandleStatus, error::AppError> http::ReadingBodyState::handle(ReadBuffer &readBuf) { | ||
while (body_.size() < contentLength_) { | ||
const std::size_t want = contentLength_ - body_.size(); | ||
const std::string chunk = readBuf.consume(want); | ||
if (chunk.empty()) { | ||
return Ok(HandleStatus::kSuspend); | ||
} | ||
body_ += chunk; | ||
} | ||
|
||
reader_.setBody(body_); | ||
reader_.changeState(NULL); | ||
|
||
return Ok(HandleStatus::kDone); | ||
} |
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,19 @@ | ||
#ifndef SRC_LIB_HTTP_REQUEST_READER_READING_BODY_STATE_HPP | ||
#define SRC_LIB_HTTP_REQUEST_READER_READING_BODY_STATE_HPP | ||
|
||
#include "./request_reader.hpp" | ||
|
||
namespace http { | ||
class ReadingBodyState : public RequestReader::IState { | ||
public: | ||
ReadingBodyState(RequestReader &reader, std::size_t contentLength); | ||
Result<HandleStatus, error::AppError> handle(ReadBuffer &readBuf); | ||
|
||
private: | ||
RequestReader &reader_; | ||
std::size_t contentLength_; | ||
std::string body_; | ||
}; | ||
} | ||
|
||
#endif |
Oops, something went wrong.