Open ymtszw opened 5 years ago
header "" "something"
headers
module Main exposing (main) import Browser import Html exposing (Html, button, div, text) import Html.Events exposing (onClick) import Http type alias Model = {} init : () -> ( Model, Cmd Msg ) init _ = ( {} , Http.request { method = "GET" , headers = [ Http.header "" "something" ] , url = "https://www.example.com" , body = Http.emptyBody , expect = Http.expectWhatever (always NoOp) , timeout = Nothing , tracker = Nothing } ) type Msg = NoOp update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of NoOp -> ( model, Cmd.none ) view : Model -> Html Msg view model = div [] [] main : Program () Model Msg main = Browser.element { init = init , view = view , update = update , subscriptions = always Sub.none }
Uncaught SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': '' is not a valid HTTP header field name.
On the other hand, empty "value" does not cause exception.
What I actually wanted was, conditionally adding/not adding a Http.header based on a variable like so:
Http.header
... , headers = [ case fooBar of Foo str -> Http.header "foo" str Bar -> Http.header "" "" , ... ] ...
but as it turned out it ends up in a runtime exception.
Http.header "" "something"
setRequestHeader()
none
The latter could be useful since it can be used paired with if or case inside Lists, like I wanted to do.
if
case
As for my intent, for now we can just wrap it in a List for the same effect:
... , headers = case fooBar of Foo str -> [ Http.header "foo" str ] Bar -> [] , ... ] ...
Steps to reproduce:
header "" "something"
inheaders
list for any Http requestResult (runtime exception)
On the other hand, empty "value" does not cause exception.
Expected behavior/Proposal
What I actually wanted was, conditionally adding/not adding a
Http.header
based on a variable like so:but as it turned out it ends up in a runtime exception.
Http.header "" "something"
should either:setRequestHeader()
at runtime (effectivelynone
for header)The latter could be useful since it can be used paired with
if
orcase
inside Lists, like I wanted to do.As for my intent, for now we can just wrap it in a List for the same effect: