@@ -52,24 +52,23 @@ internal static IResult HandleStatusRequestAsync(
5252 [ FromServices ] TeapotStatusCodeMetadataCollection statusCodes
5353 )
5454 {
55- ResponseOptions options = new ( status )
55+ TeapotStatusCodeMetadata statusData = statusCodes . TryGetValue ( status , out TeapotStatusCodeMetadata ? value ) ?
56+ value :
57+ new TeapotStatusCodeMetadata { Description = $ "{ status } Unknown Code" } ;
58+
59+ ResponseOptions options = new ( status , statusData )
5660 {
5761 Sleep = sleep ,
5862 SuppressBody = suppressBody
5963 } ;
60- return CommonHandleStatusRequestAsync ( options , wildcard , req , statusCodes ) ;
64+ return CommonHandleStatusRequestAsync ( options , wildcard , req ) ;
6165 }
6266
6367 internal static IResult CommonHandleStatusRequestAsync (
6468 ResponseOptions options ,
6569 string ? wildcard ,
66- HttpRequest req ,
67- TeapotStatusCodeMetadataCollection statusCodes
68- )
70+ HttpRequest req )
6971 {
70- TeapotStatusCodeMetadata statusData = statusCodes . TryGetValue ( options . StatusCode , out TeapotStatusCodeMetadata ? value ) ?
71- value :
72- new TeapotStatusCodeMetadata { Description = $ "{ options . StatusCode } Unknown Code" } ;
7372 options . Sleep ??= ParseHeaderInt ( req , SLEEP_HEADER ) ;
7473 options . SleepAfterHeaders ??= ParseHeaderInt ( req , SLEEP_AFTER_HEADERS ) ;
7574 options . SuppressBody ??= ParseHeaderBool ( req , SUPPRESS_BODY_HEADER ) ;
@@ -78,8 +77,7 @@ TeapotStatusCodeMetadataCollection statusCodes
7877 options . AbortBeforeHeaders ??= ParseHeaderBool ( req , ABORT_BEFORE_HEADERS ) ;
7978 options . AbortDuringBody ??= ParseHeaderBool ( req , ABORT_DURING_BODY ) ;
8079
81-
82- Dictionary < string , StringValues > customResponseHeaders = req . Headers
80+ options . CustomHeaders = req . Headers
8381 . Where ( header => header . Key . StartsWith ( CUSTOM_RESPONSE_HEADER_PREFIX , StringComparison . InvariantCultureIgnoreCase ) )
8482 . ToDictionary (
8583 header => header . Key . Replace ( CUSTOM_RESPONSE_HEADER_PREFIX , string . Empty , StringComparison . InvariantCultureIgnoreCase ) ,
@@ -98,8 +96,13 @@ internal static IResult HandleRandomRequest(
9896 {
9997 try
10098 {
101- var options = new ResponseOptions ( GetRandomStatus ( range ) ) ;
102- return CommonHandleStatusRequestAsync ( options , wildcard , req , statusCodes ) ;
99+ var status = GetRandomStatus ( range ) ;
100+ TeapotStatusCodeMetadata statusData = statusCodes . TryGetValue ( status , out TeapotStatusCodeMetadata ? value ) ?
101+ value :
102+ new TeapotStatusCodeMetadata { Description = $ "{ status } Unknown Code" } ;
103+
104+ ResponseOptions options = new ( status , statusData ) ;
105+ return CommonHandleStatusRequestAsync ( options , wildcard , req ) ;
103106 }
104107 catch
105108 {
0 commit comments