@@ -544,22 +544,20 @@ void windows_request_context::read_headers_io_completion(DWORD error_code, DWORD
544544 }
545545 else
546546 {
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;
556548 try
557549 {
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 ));
559554 }
560555 catch (const uri_exception &e)
561556 {
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 ();
563561 }
564562 m_msg.set_method (parse_request_method (m_request));
565563 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
569567 read_request_body_chunk ();
570568
571569 // 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+ }
573578 }
574579}
575580
0 commit comments