x-forwarded-for: Added allowForwardProtoMultiple option

This commit is contained in:
warp03 2023-09-14 23:39:57 +02:00
parent b54ec9dcdf
commit 02a62e58c3
Signed by: warp03
GPG Key ID: B6D2AC20BD3262DA
2 changed files with 9 additions and 2 deletions
x-forwarded-for
README.md
main/java/org/omegazero/proxyplugin/xforwardedfor

@ -19,4 +19,5 @@ Configuration ID: `xforwardedfor`
| enableUpstream | boolean | Enable adding XFF headers or header values in forwarded requests. Note that any existing XFF header values will still be forwarded if this is `false`. | no | `true` |
| forwardHeader | boolean | Enable forwarding an existing XFF and XFP header value in a request. | no | `true` |
| enableForwardProto | boolean | Enable adding a XFP header in forwarded requests. | no | `true` |
| allowForwardProtoMultiple | boolean | If `true`, new values of `x-forwarded-proto` will be added to previous values (forming a list); this may not be supported by all servers. Otherwise, the header is overwritten with the newest value. To retain a previous value, set `enableForwardProto` to `false` instead. | no | `true` |

@ -57,6 +57,8 @@ public class XForwardedForPlugin {
private boolean forwardHeader = true;
@ConfigurationOption
private boolean enableForwardProto = true;
@ConfigurationOption
private boolean allowForwardProtoMultiple = true;
private Object[] expectedParts;
@ -100,8 +102,12 @@ public class XForwardedForPlugin {
}
if(this.enableUpstream)
http.appendHeader(HEADER_XFF, addressToString((InetSocketAddress) downstreamConnection.getRemoteAddress(), this.includePortNumber));
if(this.enableForwardProto)
http.appendHeader(HEADER_XFP, http.getScheme());
if(this.enableForwardProto){
if(this.allowForwardProtoMultiple)
http.appendHeader(HEADER_XFP, http.getScheme());
else
http.setHeader(HEADER_XFP, http.getScheme());
}
}