MySQL 8.0.39
Source Code Documentation
|
#include "mysqlrouter/rest_api_utils.h"
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include "mysql/harness/utility/string.h"
#include "mysqlrouter/http_auth_realm_component.h"
#include "mysqlrouter/http_server_component.h"
Functions | |
void | send_json_document (HttpRequest &req, HttpStatusCode::key_type status_code, const rapidjson::Document &json_doc) |
send json document as HTTP response. More... | |
void | send_rfc7807_error (HttpRequest &req, HttpStatusCode::key_type status_code, const std::map< std::string, std::string > &fields) |
send a JsonProblem HTTP response. More... | |
void | send_rfc7807_not_found_error (HttpRequest &req) |
send a JsonProblem "Not Found" error. More... | |
bool | ensure_http_method (HttpRequest &req, HttpMethod::Bitset allowed_methods) |
ensure HTTP method is allowed. More... | |
bool | ensure_auth (HttpRequest &req, const std::string require_realm) |
ensure request is authenticated. More... | |
bool | ensure_no_params (HttpRequest &req) |
ensure request has no parameters. More... | |
bool | ensure_modified_since (HttpRequest &req, time_t last_modified) |
ensure resource has modified since client received it. More... | |
bool ensure_auth | ( | HttpRequest & | req, |
const std::string | require_realm | ||
) |
ensure request is authenticated.
sends HTTP-response with status 401 if authentication was not successful.
true | if request is authenticaticated |
false | if authentication was not successful and HTTP response has been sent |
bool ensure_http_method | ( | HttpRequest & | req, |
HttpMethod::Bitset | allowed_methods | ||
) |
ensure HTTP method is allowed.
sends HTTP-response with status 405 if method is not allowed and sets Allow
HTTP header.
true | if HTTP method is allowed |
false | if HTTP is not allowed and HTTP response has been sent |
bool ensure_modified_since | ( | HttpRequest & | req, |
time_t | last_modified | ||
) |
ensure resource has modified since client received it.
sends HTTP-response with status 304 if client has a newer version that
true | if resource is modified since client received it. |
false | if client has the same resource and HTTP response has been sent |
bool ensure_no_params | ( | HttpRequest & | req | ) |
ensure request has no parameters.
sends HTTP-response with status 400 if request contained a query string.
true | if request did not contain a query-string |
false | if request contained a query-string and HTTP response has been sent |
void send_json_document | ( | HttpRequest & | req, |
HttpStatusCode::key_type | status_code, | ||
const rapidjson::Document & | json_doc | ||
) |
send json document as HTTP response.
Content-Type must be sent before the function is called.
req | HttpRequest object to send error-msg |
status_code | HTTP Status code of the problem message |
json_doc | json document to send as response |
void send_rfc7807_error | ( | HttpRequest & | req, |
HttpStatusCode::key_type | status_code, | ||
const std::map< std::string, std::string > & | fields | ||
) |
send a JsonProblem HTTP response.
RFC 7807 defines application/problem+json
:
req | HttpRequest object to send error-msg |
status_code | HTTP Status code of the problem message |
fields | fields on the problem message |
void send_rfc7807_not_found_error | ( | HttpRequest & | req | ) |
send a JsonProblem "Not Found" error.
req | HttpRequest object to send error-msg |