Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ozangoktan committed Nov 7, 2023
1 parent d162e65 commit a15c09d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/HttpHandler/Logging.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ module Logging =
let private reqex =
Regex(@"\{(.+?)(\[(.+?)\])?\}", RegexOptions.Multiline ||| RegexOptions.Compiled)

let private getHeaderValue (headers: Map<string,seq<string>>) (key : string): string =
let private getHeaderValue (headers: Map<string, seq<string>>) (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
Expand All @@ -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) :> _
Expand Down
22 changes: 14 additions & 8 deletions test/Fetch.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}))

Expand All @@ -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
Expand Down Expand Up @@ -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
}))

Expand All @@ -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
Expand Down

0 comments on commit a15c09d

Please sign in to comment.