[swift-server-dev] Non-String header values
Helge Heß
me at helgehess.eu
Sun Apr 9 07:07:39 CDT 2017
Hi,
when mentioning that HTTP header values are ISO-Latin-1 as per HTTP/1.1 spec (and that I see issues w/ using String due to potential legacy-encoding-pain, e.g. with form uploads), Johannes pointed me to this:
https://tools.ietf.org/html/rfc7230#section-3.2.4
Historically, HTTP has allowed field content with text in the ISO-8859-1 charset
.. A recipient SHOULD treat other ***octets*** in field
content (obs-text) as ***opaque data***.
or in other words, something like this:
var headers : [ String : String ]
should actually be
var headers : [ String : Data ]
which of course is inconvenient. Someone already mentioned the idea of using different value types for the header values, which I think is a good idea for various reasons. I first thought maybe an enum
enum HTTPHeaderValue {
case string(String)
case octets(Data)
case int(Int)
case mimeType(MediaType)
}
but then the type is really is attached to the specific header, so I’m a little back to also using enums for headers:
enum HTTPHeader {
case contentLength(Int)
case contentType(MediaType)
case accept([MediaTypePattern])
...
case other(String, Data) // name, value
}
var headers : [ HTTPHeader ]
Just an idea.
hh
More information about the swift-server-dev
mailing list