Skip to content

Set correct value of X-Forwarded-For header in PreAuthorize request

Adam Niedzielski requested to merge x-forwarded-for-pre-authorize into master

Closes #82 (closed)

This is my first "real" Go code 🎺. Shamelessly copied from https://github.com/golang/go/blob/5bfba30d3325d87ef89dd877f05e5d1e2d618bc3/src/net/http/httputil/reverseproxy.go#L193.

If you are curious why strings.Join(prior, ", ") is necessary:

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

This probably needs some tests.

/cc @nick.thomas

Merge request reports