diff --git a/src/HttpHandler/Logging.fs b/src/HttpHandler/Logging.fs index 9a74000..7f8e94b 100644 --- a/src/HttpHandler/Logging.fs +++ b/src/HttpHandler/Logging.fs @@ -15,11 +15,12 @@ module Logging = let private reqex = Regex(@"\{(.+?)(\[(.+?)\])?\}", RegexOptions.Multiline ||| RegexOptions.Compiled) - let private getHeaderValue (headers: Map>) (key : string): string = + let private getHeaderValue (headers: Map>) (key: string) : string = match headers.TryGetValue(key) with - | (true, v) -> - match Seq.tryHead v with | first -> if first.IsSome then first.Value else String.Empty - | (false, _) -> String.Empty + | (true, v) -> + match Seq.tryHead v with + | first -> if first.IsSome then first.Value else String.Empty + | (false, _) -> String.Empty let private log' logLevel ctx content = match ctx.Request.Logger with @@ -43,7 +44,7 @@ module Logging = |> Option.toObj :> _ | PlaceHolder.ResponseContent -> content :> _ - | PlaceHolder.ResponseHeader -> + | PlaceHolder.ResponseHeader -> // GroupCollection returns empty string values for indexes beyond what was captured, therefore // we don't cause an exception here if the optional second group was not captured getHeaderValue (ctx.Response.Headers) (match'.Groups.[3].Value) :> _ diff --git a/test/Fetch.fs b/test/Fetch.fs index 318a19a..bbbbab0 100644 --- a/test/Fetch.fs +++ b/test/Fetch.fs @@ -116,9 +116,9 @@ let ``Get with logging is OK`` () = (task { let responseMessage = new HttpResponseMessage(HttpStatusCode.OK) responseMessage.Content <- new PushStreamContent("42") - responseMessage.Headers.Add("test", value="test-value") - responseMessage.Headers.Add("test2", value="not-included-in-log") - responseMessage.Headers.Add("X-Request-ID", value="test-request-id") + responseMessage.Headers.Add("test", value = "test-value") + responseMessage.Headers.Add("test2", value = "not-included-in-log") + responseMessage.Headers.Add("X-Request-ID", value = "test-request-id") return responseMessage })) @@ -132,7 +132,10 @@ let ``Get with logging is OK`` () = |> withMetrics metrics |> withLogger logger |> withLogLevel LogLevel.Debug - |> withLogFormat (HttpContext.defaultLogFormat + "\n← {ResponseHeader[test]}\n← {ResponseHeader[X-Request-ID]}\n← {ResponseHeader}") + |> withLogFormat ( + HttpContext.defaultLogFormat + + "\n← {ResponseHeader[test]}\n← {ResponseHeader[X-Request-ID]}\n← {ResponseHeader}" + ) |> cache // Act @@ -171,9 +174,9 @@ let ``Post with logging is OK`` () = retries <- retries + 1 let responseMessage = new HttpResponseMessage(HttpStatusCode.OK) responseMessage.Content <- new PushStreamContent("""{ "pong": 42 }""") - responseMessage.Headers.Add("test", value="test-value") - responseMessage.Headers.Add("test2", value="not-included-in-log") - responseMessage.Headers.Add("X-Request-ID", value="test-request-id") + responseMessage.Headers.Add("test", value = "test-value") + responseMessage.Headers.Add("test2", value = "not-included-in-log") + responseMessage.Headers.Add("X-Request-ID", value = "test-request-id") return responseMessage })) @@ -189,7 +192,10 @@ let ``Post with logging is OK`` () = |> withHeader ("api-key", "test-key") |> withLogger (logger) |> withLogLevel LogLevel.Debug - |> withLogFormat (HttpContext.defaultLogFormat + "\n← {ResponseHeader[test]}\n← {ResponseHeader[X-Request-ID]}\n← {ResponseHeader}") + |> withLogFormat ( + HttpContext.defaultLogFormat + + "\n← {ResponseHeader[test]}\n← {ResponseHeader[X-Request-ID]}\n← {ResponseHeader}" + ) |> cache // Act