Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Falco/RequestValue.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ module RequestValue =
acc

let parseRequestPrimitive (x : string) =
let decoded = WebUtility.UrlDecode x
match decoded with
match x with
| IsNullOrWhiteSpace _ -> RNull
| IsTrue x
| IsFalse x -> RBool x
Expand Down Expand Up @@ -208,7 +207,7 @@ module RequestValue =
let private routeKeyValues (route : RouteValueDictionary) =
route
|> Seq.map (fun kvp ->
kvp.Key, seq { Convert.ToString(kvp.Value, Globalization.CultureInfo.InvariantCulture) })
kvp.Key, seq { Convert.ToString(kvp.Value, Globalization.CultureInfo.InvariantCulture) |> WebUtility.UrlDecode })

let private queryKeyValues (query : IQueryCollection) =
query
Expand Down
14 changes: 14 additions & 0 deletions test/Falco.IntegrationTests.App/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ let endpoints =
mapPost "/hello/{name?}" mapRouteData
(fun person -> Request.mapForm (mapRequestData person) Response.ofJson)

get "/hello-query"
(
Request.mapQuery
(fun r ->
let name = r?name.AsStringNonEmpty("world")
$"Hello {name}!") Response.ofPlainText)

post "/hello-form"
(
Request.mapForm
(fun r ->
let name = r?name.AsStringNonEmpty("world")
$"Hello {name}!") Response.ofPlainText)

mapGet "/plug/{name?}"
(fun r -> r?name.AsStringNonEmpty("world"))
(fun name ctx ->
Expand Down
19 changes: 19 additions & 0 deletions test/Falco.IntegrationTests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,30 @@ module Tests =
let content = response.Content.ReadAsStringAsync().Result
Assert.Equal("""{"Message":"Hello John!"}""", content)

let response = client.PostAsync("/hello/John+Smith", form).Result
let content = response.Content.ReadAsStringAsync().Result
Assert.Equal("""{"Message":"Hello John Smith!"}""", content)

use form = new FormUrlEncodedContent(dict [ ("age", "42") ])
let response = client.PostAsync("/hello/John", form).Result
let content = response.Content.ReadAsStringAsync().Result
Assert.Equal("""{"Message":"Hello John, you are 42 years old!"}""", content)

[<Fact>]
let ``Receive mapped form response from: POST /hello-form`` () =
use client = factory.CreateClient ()
use form = new FormUrlEncodedContent(dict [("name", "Mr ++ ")])
let response = client.PostAsync("/hello-form", form).Result
let content = response.Content.ReadAsStringAsync().Result
Assert.Equal("Hello Mr ++ !", content)

[<Fact>]
let ``Receive mapped query response from: GET /hello-query`` () =
use client = factory.CreateClient ()
let response = client.GetAsync("/hello-query?name=Mr%20%2B%2B").Result
let content = response.Content.ReadAsStringAsync().Result
Assert.Equal("Hello Mr ++!", content)

[<Fact>]
let ``Receive utf8 text/plain response from: GET /plug/name?`` () =
use client = factory.CreateClient ()
Expand Down