Google format
This commit is contained in:
74
request.h
74
request.h
@@ -13,61 +13,61 @@ namespace firecgi {
|
||||
class Connection;
|
||||
|
||||
class Request {
|
||||
public:
|
||||
Request(Connection *conn);
|
||||
~Request();
|
||||
public:
|
||||
Request(Connection* conn);
|
||||
~Request();
|
||||
|
||||
void NewRequest(uint16_t request_id);
|
||||
void NewRequest(uint16_t request_id);
|
||||
|
||||
uint16_t RequestId() const;
|
||||
uint16_t RequestId() const;
|
||||
|
||||
void AddParam(const std::string_view& key, const std::string_view& value);
|
||||
void SetBody(const std::string_view& in);
|
||||
void AddParam(const std::string_view& key, const std::string_view& value);
|
||||
void SetBody(const std::string_view& in);
|
||||
|
||||
const std::string_view& GetParam(const std::string_view& key) const;
|
||||
const std::string_view& GetBody() const;
|
||||
const std::string_view& GetParam(const std::string_view& key) const;
|
||||
const std::string_view& GetBody() const;
|
||||
|
||||
void OnClose(const std::function<void()>& callback);
|
||||
void OnClose(const std::function<void()>& callback);
|
||||
|
||||
void WriteHeader(const std::string_view& name, const std::string_view& value);
|
||||
void WriteBody(const std::string_view& body);
|
||||
[[nodiscard]] bool Flush();
|
||||
bool End();
|
||||
void WriteHeader(const std::string_view& name, const std::string_view& value);
|
||||
void WriteBody(const std::string_view& body);
|
||||
[[nodiscard]] bool Flush();
|
||||
bool End();
|
||||
|
||||
template<typename...Args>
|
||||
void WriteBody(const std::string_view& first, Args... more);
|
||||
template <typename... Args>
|
||||
void WriteBody(const std::string_view& first, Args... more);
|
||||
|
||||
template<typename T>
|
||||
T InTransaction(const std::function<T()>& callback);
|
||||
template <typename T>
|
||||
T InTransaction(const std::function<T()>& callback);
|
||||
|
||||
private:
|
||||
Header OutputHeader();
|
||||
iovec OutputVec();
|
||||
private:
|
||||
Header OutputHeader();
|
||||
iovec OutputVec();
|
||||
|
||||
Connection *conn_;
|
||||
uint16_t request_id_ = 0;
|
||||
Connection* conn_;
|
||||
uint16_t request_id_ = 0;
|
||||
|
||||
std::unordered_map<std::string_view, std::string_view> params_;
|
||||
std::string_view body_;
|
||||
std::unordered_map<std::string_view, std::string_view> params_;
|
||||
std::string_view body_;
|
||||
|
||||
std::function<void()> on_close_;
|
||||
std::function<void()> on_close_;
|
||||
|
||||
firebuf::Buffer out_buf_;
|
||||
bool body_written_;
|
||||
std::recursive_mutex output_mu_;
|
||||
firebuf::Buffer out_buf_;
|
||||
bool body_written_;
|
||||
std::recursive_mutex output_mu_;
|
||||
};
|
||||
|
||||
template<typename...Args>
|
||||
template <typename... Args>
|
||||
void Request::WriteBody(const std::string_view& first, Args... more) {
|
||||
std::lock_guard<std::recursive_mutex> l(output_mu_);
|
||||
WriteBody(first);
|
||||
WriteBody(more...);
|
||||
std::lock_guard<std::recursive_mutex> l(output_mu_);
|
||||
WriteBody(first);
|
||||
WriteBody(more...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
T Request::InTransaction(const std::function<T()>& callback) {
|
||||
std::lock_guard<std::recursive_mutex> l(output_mu_);
|
||||
return callback();
|
||||
std::lock_guard<std::recursive_mutex> l(output_mu_);
|
||||
return callback();
|
||||
}
|
||||
|
||||
} // namespace firecgi
|
||||
} // namespace firecgi
|
||||
|
||||
Reference in New Issue
Block a user