@@ -360,10 +360,7 @@ impl RustApi {
360360 // Add Swagger UI endpoint
361361 let docs_handler = move || {
362362 let url = openapi_url. clone ( ) ;
363- async move {
364- let html = rustapi_openapi:: swagger_ui_html ( & url) ;
365- html
366- }
363+ async move { rustapi_openapi:: swagger_ui_html ( & url) }
367364 } ;
368365
369366 self . route ( & openapi_path, get ( spec_handler) )
@@ -453,32 +450,36 @@ impl RustApi {
453450 let expected_auth_docs = expected_auth;
454451
455452 // Create spec handler with auth check
456- let spec_handler: crate :: handler:: BoxedHandler = std:: sync:: Arc :: new ( move |req : crate :: Request | {
457- let json = spec_json. clone ( ) ;
458- let expected = expected_auth_spec. clone ( ) ;
459- Box :: pin ( async move {
460- if !check_basic_auth ( & req, & expected) {
461- return unauthorized_response ( ) ;
462- }
463- http:: Response :: builder ( )
464- . status ( http:: StatusCode :: OK )
465- . header ( http:: header:: CONTENT_TYPE , "application/json" )
466- . body ( http_body_util:: Full :: new ( bytes:: Bytes :: from ( json) ) )
467- . unwrap ( )
468- } ) as std:: pin:: Pin < Box < dyn std:: future:: Future < Output = crate :: Response > + Send > >
469- } ) ;
453+ let spec_handler: crate :: handler:: BoxedHandler =
454+ std:: sync:: Arc :: new ( move |req : crate :: Request | {
455+ let json = spec_json. clone ( ) ;
456+ let expected = expected_auth_spec. clone ( ) ;
457+ Box :: pin ( async move {
458+ if !check_basic_auth ( & req, & expected) {
459+ return unauthorized_response ( ) ;
460+ }
461+ http:: Response :: builder ( )
462+ . status ( http:: StatusCode :: OK )
463+ . header ( http:: header:: CONTENT_TYPE , "application/json" )
464+ . body ( http_body_util:: Full :: new ( bytes:: Bytes :: from ( json) ) )
465+ . unwrap ( )
466+ } )
467+ as std:: pin:: Pin < Box < dyn std:: future:: Future < Output = crate :: Response > + Send > >
468+ } ) ;
470469
471470 // Create docs handler with auth check
472- let docs_handler: crate :: handler:: BoxedHandler = std:: sync:: Arc :: new ( move |req : crate :: Request | {
473- let url = openapi_url. clone ( ) ;
474- let expected = expected_auth_docs. clone ( ) ;
475- Box :: pin ( async move {
476- if !check_basic_auth ( & req, & expected) {
477- return unauthorized_response ( ) ;
478- }
479- rustapi_openapi:: swagger_ui_html ( & url)
480- } ) as std:: pin:: Pin < Box < dyn std:: future:: Future < Output = crate :: Response > + Send > >
481- } ) ;
471+ let docs_handler: crate :: handler:: BoxedHandler =
472+ std:: sync:: Arc :: new ( move |req : crate :: Request | {
473+ let url = openapi_url. clone ( ) ;
474+ let expected = expected_auth_docs. clone ( ) ;
475+ Box :: pin ( async move {
476+ if !check_basic_auth ( & req, & expected) {
477+ return unauthorized_response ( ) ;
478+ }
479+ rustapi_openapi:: swagger_ui_html ( & url)
480+ } )
481+ as std:: pin:: Pin < Box < dyn std:: future:: Future < Output = crate :: Response > + Send > >
482+ } ) ;
482483
483484 // Create method routers with boxed handlers
484485 let mut spec_handlers = HashMap :: new ( ) ;
@@ -509,7 +510,7 @@ impl RustApi {
509510 // Prepend body limit layer so it's the first to process requests
510511 self . layers . prepend ( Box :: new ( BodyLimitLayer :: new ( limit) ) ) ;
511512 }
512-
513+
513514 let server = Server :: new ( self . router , self . layers ) ;
514515 server. run ( addr) . await
515516 }
@@ -546,8 +547,13 @@ fn check_basic_auth(req: &crate::Request, expected: &str) -> bool {
546547fn unauthorized_response ( ) -> crate :: Response {
547548 http:: Response :: builder ( )
548549 . status ( http:: StatusCode :: UNAUTHORIZED )
549- . header ( http:: header:: WWW_AUTHENTICATE , "Basic realm=\" API Documentation\" " )
550+ . header (
551+ http:: header:: WWW_AUTHENTICATE ,
552+ "Basic realm=\" API Documentation\" " ,
553+ )
550554 . header ( http:: header:: CONTENT_TYPE , "text/plain" )
551- . body ( http_body_util:: Full :: new ( bytes:: Bytes :: from ( "Unauthorized" ) ) )
555+ . body ( http_body_util:: Full :: new ( bytes:: Bytes :: from (
556+ "Unauthorized" ,
557+ ) ) )
552558 . unwrap ( )
553559}
0 commit comments