#Reading input that might extend a type

8 messages · Page 1 of 1 (latest)

haughty umbra
#

So I want to read the Headers of an HTTP request and put them into a Request. There are headers that are defined by the HTTP standard but you can also set your own. Is there any way to treat these two the same, but not just as strings? What I mean is: I'd like to be able to do req.headers.headername in both cases

#

(Like I would be able to in JS/express for example)

normal verge
#

HeaderMap can store a maximum of 32,768 headers (header name / value pairs).

haughty umbra
#

😄 Sorry, don't want to use any crates as this is for learning.

meager hill
haughty umbra
#

Okay thanks! Now that I think about it, I guess my question comes down to if there is a way to offer the Header type in a library and then to extend that type with custom headers in the code that uses that library? Not at runtime, but when the library-using application code is written

#

(Because I now realise that supporting arbitrary headers doesn't make much sense really, since the app needs to interpret them anyways)