@@ -310,50 +310,10 @@ async fn serve_req(server: Server, req: Request) -> Result<Response, ServerError
310
310
. handle_get_async ( & req, |c| request_handlers:: handle_next_commit ( c) )
311
311
. await ;
312
312
}
313
- "/perf/triage" => {
314
- let input: triage:: Request = if * req. method ( ) == http:: Method :: GET {
315
- check ! ( parse_query_string( req. uri( ) ) )
316
- } else if * req. method ( ) == http:: Method :: POST {
317
- let mut body = Vec :: new ( ) ;
318
- let ( _req, mut body_stream) = req. into_parts ( ) ;
319
- while let Some ( chunk) = body_stream. next ( ) . await {
320
- let chunk =
321
- chunk. map_err ( |e| ServerError ( format ! ( "failed to read chunk: {:?}" , e) ) ) ?;
322
- body. extend_from_slice ( & chunk) ;
323
- // More than 10 MB of data
324
- if body. len ( ) > 1024 * 1024 * 10 {
325
- return Ok ( http:: Response :: builder ( )
326
- . status ( StatusCode :: PAYLOAD_TOO_LARGE )
327
- . body ( hyper:: Body :: empty ( ) )
328
- . unwrap ( ) ) ;
329
- }
330
- }
331
- match parse_body ( & body) {
332
- Ok ( b) => b,
333
- Err ( e) => return Ok ( e) ,
334
- }
335
- } else {
336
- return Ok ( http:: Response :: builder ( )
337
- . status ( StatusCode :: BAD_REQUEST )
338
- . header_typed ( ContentType :: text_utf8 ( ) )
339
- . body ( hyper:: Body :: from ( "bad method, only GET and POST supported" ) )
340
- . unwrap ( ) ) ;
341
- } ;
313
+ "/perf/triage" if * req. method ( ) == http:: Method :: GET => {
342
314
let ctxt: Arc < SiteCtxt > = server. ctxt . read ( ) . as_ref ( ) . unwrap ( ) . clone ( ) ;
343
- let response = crate :: comparison:: handle_triage ( input, & ctxt) . await ;
344
- match response {
345
- Ok ( result) => {
346
- let response = http:: Response :: builder ( ) . header_typed ( ContentType :: text ( ) ) ;
347
- return Ok ( response. body ( hyper:: Body :: from ( result. 0 ) ) . unwrap ( ) ) ;
348
- }
349
- Err ( err) => {
350
- return Ok ( http:: Response :: builder ( )
351
- . status ( StatusCode :: INTERNAL_SERVER_ERROR )
352
- . header_typed ( ContentType :: text_utf8 ( ) )
353
- . body ( hyper:: Body :: from ( err. to_string ( ) ) )
354
- . unwrap ( ) )
355
- }
356
- }
315
+ let input: triage:: Request = check ! ( parse_query_string( req. uri( ) ) ) ;
316
+ return Ok ( to_triage_response ( crate :: comparison:: handle_triage ( input, & ctxt) . await ) ) ;
357
317
}
358
318
"/perf/metrics" => {
359
319
return Ok ( server. handle_metrics ( req) . await ) ;
@@ -491,6 +451,9 @@ async fn serve_req(server: Server, req: Request) -> Result<Response, ServerError
491
451
. unwrap ( ) ,
492
452
} ,
493
453
) ,
454
+ "/perf/triage" => Ok ( to_triage_response (
455
+ crate :: comparison:: handle_triage ( check ! ( parse_body( & body) ) , & ctxt) . await
456
+ ) ) ,
494
457
_ => Ok ( http:: Response :: builder ( )
495
458
. header_typed ( ContentType :: html ( ) )
496
459
. status ( StatusCode :: NOT_FOUND )
@@ -637,6 +600,22 @@ where
637
600
}
638
601
}
639
602
603
+ fn to_triage_response ( result : ServerResult < api:: triage:: Response > ) -> Response {
604
+ match result {
605
+ Ok ( result) => {
606
+ let response = http:: Response :: builder ( ) . header_typed ( ContentType :: text ( ) ) ;
607
+ response. body ( hyper:: Body :: from ( result. 0 ) ) . unwrap ( )
608
+ }
609
+ Err ( err) => {
610
+ http:: Response :: builder ( )
611
+ . status ( StatusCode :: INTERNAL_SERVER_ERROR )
612
+ . header_typed ( ContentType :: text_utf8 ( ) )
613
+ . body ( hyper:: Body :: from ( err. to_string ( ) ) )
614
+ . unwrap ( )
615
+ }
616
+ }
617
+ }
618
+
640
619
async fn run_server ( ctxt : Arc < RwLock < Option < Arc < SiteCtxt > > > > , addr : SocketAddr ) {
641
620
let server = Server :: new ( ctxt) ;
642
621
let svc = hyper:: service:: make_service_fn ( move |_conn| {
0 commit comments