-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make logfn
optional
#133
Comments
Hi @64J0 and thanks for the issue. I'm not sure what's your exact use case, so let me explain how it is meant to work:
Can you explain your use case, and if there's still an issue after all? Thank you. |
Nice, I was not aware of this configuration! Thanks for the information @RonaldSchlenker. To give more context, I'm using an FSI script to trigger some requests,: dotnet fsi samples/ResponseCachingApp/test-run.fsx After adding the |
I'll close this issue now, thanks again @RonaldSchlenker! |
Nice, glad we could solve it :) Have a nice day! |
I'm using it on this PR -> giraffe-fsharp/Giraffe#553 |
Nice that you contribute to Giraffe! I have seen the fsx, and wanted to ask you what do you think of some changes: #r "nuget: FsHttp, 11.0.0"
open System
open FsHttp
// Uncomment if you don't want FsHttp debug logs
// Fsi.disableDebugLogs()
type QueryParams = (string * obj) list
type Url = Url of string
type Title = Title of string
let urls =
{|
notCached = Url "http://localhost:5000/cached/not"
publicCached = Url "http://localhost:5000/cached/public"
privateCached = Url "http://localhost:5000/cached/private"
publicCachedNoVaryByQueryKeys = Url "http://localhost:5000/cached/vary/not"
cachedVaryByQueryKeys = Url "http://localhost:5000/cached/vary/yes"
|}
let queryParams1: QueryParams = [ ("query1", "a"); ("query2", "b") ]
let queryParams2: QueryParams = [ ("query1", "c"); ("query2", "d") ]
let waitForOneSecond () =
do Threading.Thread.Sleep (TimeSpan.FromSeconds 1.0)
let makeRequest (Url url: Url) (queryParams: list<string * obj>) =
let response =
http {
GET url
CacheControl "max-age=3600"
query queryParams
}
|> Request.send
|> Response.toFormattedText
printfn "%s" response
printfn ""
let printRunTitle (Title title) =
printfn "-----------------------------------"
printfn "%s" title
printfn ""
let printTimeTaken (duration: TimeSpan) =
printfn "The time it took to finish:"
printfn "%.2f seconds" duration.TotalSeconds
printfn ""
let run (qps: QueryParams list) title url =
printRunTitle title
let stopWatch = Diagnostics.Stopwatch.StartNew()
for queryParams in qps do
makeRequest url queryParams |> waitForOneSecond
stopWatch.Stop()
printTimeTaken stopWatch.Elapsed
let runFiveRequests = run [ for _ in 1..5 do [] ]
let testPublicCachedNoVaryByQueryKeys () =
let allQueryParams =
[
queryParams1
queryParams1
queryParams2
queryParams2
]
let title = Title "Testing the /cached/vary/not endpoint"
let url = urls.publicCachedNoVaryByQueryKeys
run allQueryParams title url
let testCachedVaryByQueryKeys () =
let title = Title "Testing the /cached/vary/yes endpoint"
let url = urls.cachedVaryByQueryKeys
let allQueryParams =
[
queryParams1
queryParams1
queryParams2
queryParams2
]
run allQueryParams title url
let main () =
runFiveRequests (Title "Testing the /cached/not endpoint") urls.notCached
runFiveRequests (Title "Testing the /cached/public endpoint") urls.publicCached
runFiveRequests (Title "Testing the /cached/private endpoint") urls.privateCached
testPublicCachedNoVaryByQueryKeys ()
testCachedVaryByQueryKeys ()
main () The changes are basically:
You can think about it and if you like, use it. Say hi to Jimmy, and have a good day / night. P.S.: As an alternative to blocking the thread using |
Great suggestions @RonaldSchlenker, I'm going to apply it there. |
I'd like to have a toggle option to make the usage of
logfn
optional. After making several requests, it's weird to see the same string pattern appearing at the terminal. In this case, I'd prefer to not show it at all.The version I'm using is
11.0.0
.Let me know if you think this is something that we could add to this project.
The text was updated successfully, but these errors were encountered: