Repository navigation
Open
Description
- elm 0.19.0
- elm/http@2.0.0
- Chrome 71.0.3578.80
Steps to reproduce:
- Put
header "" "something"inheaderslist for any Http request
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
}Result (runtime exception)
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.
Expected behavior/Proposal
What I actually wanted was, conditionally adding/not adding a Http.header based on a variable like so:
...
, 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.
- At least we should not leak runtime exception, so
Http.header "" "something"should either:- not compile
- not try to
setRequestHeader()at runtime (effectivelynonefor header)
The latter could be useful since it can be used paired with if or case 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:
...
, headers =
case fooBar of
Foo str ->
[ Http.header "foo" str ]
Bar ->
[]
, ...
]
...Metadata
Metadata
Assignees
Labels
No labels
Activity