-
Notifications
You must be signed in to change notification settings - Fork 760
add some simple function to request and response class #133
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: manageryzy <[email protected]>
Signed-off-by: manageryzy <[email protected]>
Signed-off-by: manageryzy <[email protected]>
Signed-off-by: manageryzy <[email protected]>
Signed-off-by: manageryzy <[email protected]>
sorry for submit for three times.
|
Thank you. I'll probably merge this but am going to make some changes. One of the changes is to put some functions that are not directly related to network communication (encoding/decoding, and status codes and mime types for instance) into utility.hpp. I think I have time to look at this in 3-4 days. |
After some thought I've decided not to merge these commits, but some of the features will be added (they will look a bit different). For instance, I'll add some convenient functions like maybe: Server::Response::write(StatusCode status_code=StatusCode::ok, const std::string &content=std::string(), const CaseInsensitiveMultimap &header=CaseInsensitiveMultimap());
Server::Response::write(StatusCode status_code, std::iostream &content, const CaseInsensitiveMultimap &header=CaseInsensitiveMultimap());
// Assumes StatusCode::ok:
Server::Response::write(const std::string &content=std::string(), const CaseInsensitiveMultimap &header=CaseInsensitiveMultimap());
Server::Response::write(std::iostream &content, const CaseInsensitiveMultimap &header=CaseInsensitiveMultimap()); , where edit: renamed |
what about the easy way to set cookie , parse cooke and parse post form data? |
Yes, I will consider these functions as well. Feel free to keep this PR open until the most important functions are implemented. If I reuse some of your code, I will commit this with you as author if that is ok. Thank you again for this PR. |
Here is how you currently can parse and show post form data: server.resource["^/post_example$"]["POST"]=[](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
auto fields=SimpleWeb::QueryString::parse(request->content.string());
stringstream stream;
for(auto &field: fields)
stream << field.first << ": " << field.second << "\n";
response->write(stream);
}; |
|
add
request->parse_post()
request->parse_cookies()
to requestadd
response->set_MIME
response->headers
response->set_cookie
response->send_headers
to responsethis a simple demo