Using the HTTP response
Armed with a good understanding of Julia's dictionary data structure, we can now take a closer look at the headers
property of resp
, our HTTP
response object.
To make it easier to access the various headers, first let's convert the array of Pair
 to a Dict
:
julia> headers = Dict(resp.headers)
Dict{SubString{String},SubString{String}} with 23 entries:
"Connection" => "keep-alive"
"Via" => "1.1 varnish (Varnish/5.1), 1.1 varnish (Varni...
"X-Analytics" => "ns=0;page_id=38455554;https=1;nocookies=1"
#... output truncated... #
We can check the Content-Length
value to determine whether or not we have a response body. If it's larger than 0
, that means we got back a HTML message:
julia> headers["Content-Length"]
"193324"
It's important to remember that all the values in the headers
dictionary are strings, so we can't go comparing them straight away:
julia> headers["Content-Length"] > 0
ERROR: MethodError: no method matching isless(...