SwaggerProvider icon indicating copy to clipboard operation
SwaggerProvider copied to clipboard

DOCS Suggestion, add more extensive docs for delegating handlers as its tricky in F#

Open jkone27 opened this issue 2 years ago • 3 comments

Without having this, I had bugs in my delegating handlers when adding e.g. authorization to query

https://gist.github.com/panesofglass/a1cfc3c9a3f0d41233ad

the reason is that if just using base.SendAsync inside a task { .. } or async { ... } ce, it will fail to update the parameters and execute it in a different order. I was just assigning it to a binding outside the task and then executing it within the task but that was wrong, it only works if there is no mutation e.g. of request or response.

Shall we add this info to docs website?

jkone27 avatar Apr 24 '23 17:04 jkone27

Not sure that I fully understand

Here is current auth doc https://fsprojects.github.io/SwaggerProvider/#/Customization#authentication

and for sure you need to modify request before you call SendAsync (not matter you use task/async ce or not).

your sample should work like if you change it like this

let loggingHandler =
    { new DelegatingHandler() with
        member x.SendAsync(request, cancellationToken) = 
            task {
                 // your code here, if you change Request it will not change! beware !!!!!
                 return! base.SendAsync(request, cancellationToken)
            }
    }

what you propose to improve?

sergey-tihon avatar Apr 29 '23 12:04 sergey-tihon

mmm.. if you call base.SendAsync inside the task, the F# compiler will complain https://github.com/dotnet/fsharp/issues/12448

jkone27 avatar May 05 '23 13:05 jkone27

It is slightly surprising, but issue that you mentioned also contains workaround that can be used

sergey-tihon avatar May 05 '23 14:05 sergey-tihon