Skip to content

add methods to deal with Headers #1288

Description

@hhaensel

I'm currently adapting Genie/Stipple to v2 of HTTP and found it would be very helpful to define

function Base.setindex!(headers::Headers, value, key::Union{Symbol, AbstractString})
    item = _header_pair(key, value)
    k = first(item)
    res = findfirst(x -> first(x) == k, headers.entries)
    if res !== nothing
        headers[res] = item
    else
        push!(headers.entries, item)
    end
end

function Base.merge!(headers::Headers, items)
    for (k,v) in items
        headers[k] = v
    end
    return headers
end

Moreover, I'd appreciate

    elseif headers_input isa Pair
        _append_header_values!(headers, headers_input.first, headers_input.second)
        return headers
    end

in mkheaders()
and maybe

Headers(item::Pair) = mkheaders((item,))
Headers(items...) = mkheaders(items)

in order to support the more natural

Headers(:a => :b)
Headers(:a => :b, :c => "d")

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions