Skip to content

Commit

Permalink
fixed untracked bug: using config_useBaseUrl as a http template won't…
Browse files Browse the repository at this point in the history
… crash when printing unfinished requests
  • Loading branch information
SchlenkR authored and SchlenkR committed Aug 7, 2024
1 parent 625184c commit 20aaa45
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<FsDocsReleaseNotesLink>https://www.nuget.org/packages/FsHttp#release-body-tab</FsDocsReleaseNotesLink>

<PackageReleaseNotes>
14.5.1
- Fixed untracked bug: using config_useBaseUrl as http template won't crash when printing unfinished requests

14.5.0
- Added 'useBaseUrl' and 'transformUrl' to Config for better composability
- Fixed some extension methods
Expand Down
2 changes: 1 addition & 1 deletion docs/Composability.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let httpForMySpecialEnvironment =
// we have to change the URL for any method using a header transformer,
// like so:
config_transformHeader (fun (header: Header) ->
let address = baseUrl </> header.target.address.Value
let address = baseUrl </> (header.target.address |> Option.defaultValue "")
{ header with target.address = Some address })

// other header values can be just configured as usual:
Expand Down
31 changes: 31 additions & 0 deletions fiddle/issue-178.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#r "../src/FsHttp/bin/debug/net6.0/FsHttp.dll"

open System.IO
open System.Net.Http
open System.Net.Http.Headers
open FsHttp
open FsHttp.Operators


let httpd0 =
http {
config_transformHeader (fun (header: Header) ->
printfn "header.target: %A" header.target
printfn "header.target.address: %A" header.target.address

let address = "http://aaaa:5000" </> (header.target.address |> Option.defaultValue "")
{ header with target.address = Some address })
}



let httpd1 =
http {
config_transformUrl (fun url -> "http://aaaa:5000" </> url)
}

let httpd2 =
http {
config_useBaseUrl "http://aaaa:5000"
}
2 changes: 1 addition & 1 deletion src/FsHttp/Dsl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ module Config =

let transformUrl transformer (context: IUpdateConfig<_>) =
context |> transformHeader (fun header ->
let address = transformer header.target.address.Value
let address = transformer (header.target.address |> Option.defaultValue "")
{ header with target.address = Some address })

let useBaseUrl (baseUrl: string) (context: IUpdateConfig<_>) =
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ let [<TestCase>] ``Header Transformer``() =
let httpSpecial =
let transformWith suffix =
fun (header: Header) ->
let address = header.target.address.Value
let address = (header.target.address |> Option.defaultValue "")
{ header with target.address = Some $"{address}{suffix}" }
http {
config_transformHeader (transformWith urlSuffix1)
Expand Down

0 comments on commit 20aaa45

Please sign in to comment.