Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

Set status reason text with constructor #60

Closed seghcder closed 4 years ago

seghcder commented 4 years ago

Small suggestion - It would be good if instead of:

auto status =restinio::status_bad_request();
status.reason_phrase("Only Basic authorization currently supported");

we could do this:

auto status =restinio::status_bad_request("Only Basic authorization currently supported");

However I also read that HTTP/2 does away with text reason phrases: https://github.com/http2/http2-spec/issues/202 ... so if you are planning http/2 support soon then it might not be worth it.

eao197 commented 4 years ago

Helper functions like status_bad_request were created for cases when a user doesn't want to specify own error description. If a custom error description is necessary then underlying http_status_line_t object can be constructed directly. For example:

auto status = restinio::http_status_line_t{
      restinit::status_code::bad_request, 
      "Only Basic authorization currently supported"
};

or

restinio::http_status_line_t status{
      restinit::status_code::bad_request, 
      "Only Basic authorization currently supported"
};
seghcder commented 4 years ago

Got it :-)