GCP will lowercase header names from September 30. – I would like to update my code to only send lowercase headers

530 views
Skip to first unread message

mar...@stabenfeldt.net

unread,
Aug 27, 2019, 8:38:53 AM8/27/19
to golang-nuts
I received this email the other day:


Hello Google HTTP(S) Load Balancing Customer,
We’re writing to let you know about a change to the behavior of HTTP(S) Load Balancers that is being rolled out gradually, beginning September 30, 2019. We are making this change to standardize HTTP(S) load balancer behavior across HTTP/1.1 and more modern protocols, including HTTP/2 and QUIC.
What do I need to know?
After September 30, HTTP(S) Load Balancers will convert HTTP/1.1 header names to lowercase in the request and response directions; header values will not be affected.

I would prefer not do delegate the responsibility of my HTTP header casing to GCP. Who knows, perhaps this code will live somewhere else one day?
Is there a way I could "easily" lowercase all the HTTP headers I send?

e.g.
w.Header().Set("x-sync-token", csrf.Token(r))
Will be sent as X-Sync-Token


What do you guys do? Do you think it's necessary to update the headers sent as long as the clients are case insensitive? 



Best,
Martin

Ben Burwell

unread,
Aug 27, 2019, 9:19:23 AM8/27/19
to mar...@stabenfeldt.net, golang-nuts
> What do you guys do? Do you think it's necessary to update the headers
> sent as long as the clients are case insensitive?

Per RFC 2068 section 4.2, HTTP/1.1 headers are case insensitive. So
unless your HTTP clients don't conform to RFC 2068, I wouldn't worry
about it. Even then, you should probably just update the clients to be
compliant.

> Is there a way I could "easily" lowercase all the HTTP headers I send?
>
> e.g.
> w.Header().Set("x-sync-token", csrf.Token(r))
> Will be sent as *X-Sync-Token*

net/http uses the CanonicalHeaderKey function which sets the casing of
the headers: https://golang.org/pkg/net/http/#CanonicalHeaderKey

However, http.Header is just map[string][]string, so you could probably
just manipulate the map directly instead of using Set(). But the
built-in functions rely on CanonicalHeaderKey's casing, so you won't be
able to mix and match map manipulation with using Get/Set/Has.

I would just let Go send headers according to CanonicalHeaderKey and let
the GCP load balancer/proxy set the casing, as it shouldn't matter.
Reply all
Reply to author
Forward
0 new messages