Line folding in HTTP headers results in Nginx 502 Bad Gateway error
RFC7230 in section 3.2.4 deprecates line folding in HTTP header fields (except for one particular case). So, in a nutshell, the safest solution would be to avoid line breaks in HTTP headers.
Quote from the RFC7230 section 3.2.4:
A proxy or gateway that receives an obs-fold in a response message
that is not within a message/http container MUST either discard the
message and replace it with a 502 (Bad Gateway) response, preferably
with a representation explaining that unacceptable line folding was
received, or replace each received obs-fold with one or more SP
octets prior to interpreting the field value or forwarding the
message downstream.
Splitting the long header into several lines is tempting to make it look nice in the configuration file. But this can result in unexpected errors or behaviour. For example, Nginx sends a 502 (Bad Gateway) response when it receives such HTTP header from an upstream. This error message is very confusing because it does not give any explanations, and it is hard to guess that the cause of the error is the line breaks in the HTTP header.