@@ -544,22 +544,20 @@ void windows_request_context::read_headers_io_completion(DWORD error_code, DWORD
544
544
}
545
545
else
546
546
{
547
- // Parse headers.
548
- // CookedUrl.pFullUrl contains the canonicalized URL and it is not encoded
549
- // However, Query strings are opaque to http.sys and are passed as-is => CookedUrl.pFullUrl
550
- // contains an already encoded version of query string.
551
- uri_builder builder (uri::encode_uri (m_request->CookedUrl .pFullUrl ));
552
- if (m_request->CookedUrl .QueryStringLength != 0 )
553
- {
554
- builder.set_query (uri::decode (builder.query ()));
555
- }
547
+ std::string badRequestMsg;
556
548
try
557
549
{
558
- m_msg.set_request_uri (builder.to_uri ());
550
+ // HTTP_REQUEST::pRawUrl contains the raw URI that came across the wire.
551
+ // Use this instead since the CookedUrl is a mess of the URI components
552
+ // some encoded and some not.
553
+ m_msg.set_request_uri (utf8_to_utf16 (m_request->pRawUrl ));
559
554
}
560
555
catch (const uri_exception &e)
561
556
{
562
- m_msg.reply (status_codes::BadRequest, e.what ());
557
+ // If an exception occurred, finish processing the request below but
558
+ // respond with BadRequest instead of dispatching to the user's
559
+ // request handlers.
560
+ badRequestMsg = e.what ();
563
561
}
564
562
m_msg.set_method (parse_request_method (m_request));
565
563
parse_http_headers (m_request->Headers , m_msg.headers ());
@@ -569,7 +567,14 @@ void windows_request_context::read_headers_io_completion(DWORD error_code, DWORD
569
567
read_request_body_chunk ();
570
568
571
569
// Dispatch request to the http_listener.
572
- dispatch_request_to_listener ((web::http::experimental::listener::details::http_listener_impl *)m_request->UrlContext );
570
+ if (badRequestMsg.empty ())
571
+ {
572
+ dispatch_request_to_listener ((web::http::experimental::listener::details::http_listener_impl *)m_request->UrlContext );
573
+ }
574
+ else
575
+ {
576
+ m_msg.reply (status_codes::BadRequest, badRequestMsg);
577
+ }
573
578
}
574
579
}
575
580
0 commit comments