Skip to content

Commit 20aaa45

Browse files
SchlenkRSchlenkR
authored andcommitted
fixed untracked bug: using config_useBaseUrl as a http template won't crash when printing unfinished requests
1 parent 625184c commit 20aaa45

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<FsDocsReleaseNotesLink>https://www.nuget.org/packages/FsHttp#release-body-tab</FsDocsReleaseNotesLink>
1717

1818
<PackageReleaseNotes>
19+
14.5.1
20+
- Fixed untracked bug: using config_useBaseUrl as http template won't crash when printing unfinished requests
21+
1922
14.5.0
2023
- Added 'useBaseUrl' and 'transformUrl' to Config for better composability
2124
- Fixed some extension methods

docs/Composability.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let httpForMySpecialEnvironment =
3838
// we have to change the URL for any method using a header transformer,
3939
// like so:
4040
config_transformHeader (fun (header: Header) ->
41-
let address = baseUrl </> header.target.address.Value
41+
let address = baseUrl </> (header.target.address |> Option.defaultValue "")
4242
{ header with target.address = Some address })
4343

4444
// other header values can be just configured as usual:

fiddle/issue-178.fsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#r "../src/FsHttp/bin/debug/net6.0/FsHttp.dll"
3+
4+
open System.IO
5+
open System.Net.Http
6+
open System.Net.Http.Headers
7+
open FsHttp
8+
open FsHttp.Operators
9+
10+
11+
let httpd0 =
12+
http {
13+
config_transformHeader (fun (header: Header) ->
14+
printfn "header.target: %A" header.target
15+
printfn "header.target.address: %A" header.target.address
16+
17+
let address = "http://aaaa:5000" </> (header.target.address |> Option.defaultValue "")
18+
{ header with target.address = Some address })
19+
}
20+
21+
22+
23+
let httpd1 =
24+
http {
25+
config_transformUrl (fun url -> "http://aaaa:5000" </> url)
26+
}
27+
28+
let httpd2 =
29+
http {
30+
config_useBaseUrl "http://aaaa:5000"
31+
}

src/FsHttp/Dsl.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ module Config =
482482

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

488488
let useBaseUrl (baseUrl: string) (context: IUpdateConfig<_>) =

src/Tests/Config.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ let [<TestCase>] ``Header Transformer``() =
178178
let httpSpecial =
179179
let transformWith suffix =
180180
fun (header: Header) ->
181-
let address = header.target.address.Value
181+
let address = (header.target.address |> Option.defaultValue "")
182182
{ header with target.address = Some $"{address}{suffix}" }
183183
http {
184184
config_transformHeader (transformWith urlSuffix1)

0 commit comments

Comments
 (0)