@@ -609,6 +609,32 @@ void HttpServer::OnRequestPatchNotAllowed(mg_connection* conn, http_message* msg
609609 }
610610}
611611
612+ void HttpServer::OnRequestDownloadGzip (mg_connection* conn, http_message* msg) {
613+ if (std::string{msg->method .p , msg->method .len } == std::string{" DOWNLOAD" }) {
614+ mg_http_send_error (conn, 405 , " Method Not Allowed" );
615+ } else {
616+ std::string encoding;
617+ for (size_t i = 0 ; i < sizeof (msg->header_names ) / sizeof (mg_str); i++) {
618+ if (!msg->header_names [i].p ) {
619+ continue ;
620+ }
621+
622+ std::string name = std::string (msg->header_names [i].p , msg->header_names [i].len );
623+ if (std::string{" Accept-Encoding" } == name) {
624+ encoding = std::string (msg->header_values [i].p , msg->header_values [i].len );
625+ break ;
626+ }
627+ }
628+ if (encoding.find (" gzip" ) == std::string::npos) {
629+ mg_http_send_error (conn, 405 , (" Invalid encoding: " + encoding).c_str ());
630+ } else {
631+ std::string response = " Download!" ;
632+ mg_send_head (conn, 200 , static_cast <int >(response.length ()), " " );
633+ mg_send (conn, response.c_str (), static_cast <int >(response.length ()));
634+ }
635+ }
636+ }
637+
612638void HttpServer::OnRequest (mg_connection* conn, http_message* msg) {
613639 std::string uri = std::string (msg->uri .p , msg->uri .len );
614640 if (uri == " /" ) {
@@ -671,6 +697,8 @@ void HttpServer::OnRequest(mg_connection* conn, http_message* msg) {
671697 OnRequestPatch (conn, msg);
672698 } else if (uri == " /patch_unallowed.html" ) {
673699 OnRequestPatchNotAllowed (conn, msg);
700+ } else if (uri == " /download_gzip.html" ) {
701+ OnRequestDownloadGzip (conn, msg);
674702 } else {
675703 OnRequestNotFound (conn, msg);
676704 }
0 commit comments