fsprojects / FsHttp

A lightweight F# HTTP library by @SchlenkR and @dawedawe
https://fsprojects.github.io/FsHttp/
Apache License 2.0
424 stars 42 forks source link

Not escaped query value part #118

Closed maciej-izak closed 1 year ago

maciej-izak commented 1 year ago

Hi,

I have prepared PR : https://github.com/fsprojects/FsHttp/pull/117 . This is because during work with FsHttp I found that using library in such way :

let resp =
    http {
        GET "https://someurl"
        query [
            "limit", 1000
            "rule", foo
            "orderBy", "DateAddedDesc"
            "APIKEY", APIKEY
        ]
        CacheControl "no-cache"
    }
    |> Request.send

is very error prone. This is because value part is not escaped.

Workaround (but IMO this should be default behavior) :

let escape = List.map (fun (k, v: obj) -> k, box (Uri.EscapeDataString $"{v}"))
let resp =
    http {
        GET "https://someurl"
        query (escape [
            "limit", 1000
            "rule", foo
            "orderBy", "DateAddedDesc"
            "APIKEY", APIKEY
        ])
        CacheControl "no-cache"
    }
    |> Request.send
SchlenkR commented 1 year ago

I'll have a look at it soon. Please excuse the late reply - your work is very much appreciated!

SchlenkR commented 1 year ago

but IMO this should be default behavior

I think so, too. Closing this as PR is merged.

And of course: Thank you very much for your PR :)