-
Notifications
You must be signed in to change notification settings - Fork 39
Added support to specify Custom Hop-By-Hop Headers #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,12 @@ | |
| import io.vertx.codegen.json.annotations.JsonGen; | ||
| import io.vertx.core.json.JsonObject; | ||
| import io.vertx.httpproxy.cache.CacheOptions; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static io.vertx.core.http.HttpHeaders.*; | ||
| import static io.vertx.core.http.HttpHeaders.UPGRADE; | ||
|
|
||
| /** | ||
| * Proxy options. | ||
|
|
@@ -17,15 +23,28 @@ public class ProxyOptions { | |
| */ | ||
| public static final boolean DEFAULT_SUPPORT_WEBSOCKET = true; | ||
|
|
||
| public static final List<String> DEFAULT_HOP_BY_HOP_HEADERS = new ArrayList<>(Arrays.asList( | ||
| CONNECTION.toString(), | ||
| KEEP_ALIVE.toString(), | ||
| PROXY_AUTHENTICATE.toString(), | ||
| PROXY_AUTHORIZATION.toString(), | ||
| TRANSFER_ENCODING.toString(), | ||
| UPGRADE.toString(), | ||
| "te", | ||
| "trailer" | ||
| )); | ||
|
|
||
| private CacheOptions cacheOptions; | ||
| private boolean supportWebSocket; | ||
| private List<String> customHopHeaders; | ||
|
|
||
| public ProxyOptions(JsonObject json) { | ||
| ProxyOptionsConverter.fromJson(json, this); | ||
| } | ||
|
|
||
| public ProxyOptions() { | ||
| supportWebSocket = DEFAULT_SUPPORT_WEBSOCKET; | ||
| customHopHeaders = DEFAULT_HOP_BY_HOP_HEADERS; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -66,6 +85,30 @@ public ProxyOptions setSupportWebSocket(boolean supportWebSocket) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * @return custom hop-by-hop headers | ||
| */ | ||
| public List<String> getCustomHopHeaders() { | ||
| return customHopHeaders; | ||
| } | ||
|
|
||
| /** | ||
| * Sets custom hop-by-hop headers, overriding the default {@code DEFAULT_HOP_BY_HOP_HEADERS} headers. | ||
| * <p> | ||
| * <b>Warning:</b> Please read the following specification before removing or modifying | ||
| * any hop-by-hop header: | ||
| * <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-13.5.1"> | ||
| * RFC 2616, Section 13.5.1 | ||
| * </a> | ||
| * </p> | ||
| * | ||
| * @param customHopHeaders the list of hop-by-hop headers to set | ||
| */ | ||
| public ProxyOptions setCustomHopHeaders(List<String> customHopHeaders){ | ||
|
||
| this.customHopHeaders = customHopHeaders; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return toJson().toString(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import io.vertx.core.http.HttpVersion; | ||
| import io.vertx.core.net.HostAndPort; | ||
| import io.vertx.httpproxy.impl.ProxiedRequest; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * | ||
|
|
@@ -42,6 +43,18 @@ static ProxyRequest reverseProxy(HttpServerRequest proxiedRequest) { | |
| return new ProxiedRequest(proxiedRequest); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new {@code ProxyRequest} instance, the proxied request will be paused. | ||
| * | ||
| * @param proxiedRequest the {@code HttpServerRequest} that is proxied | ||
| * @param customHopHeaders list of Custom Hop-By-Hop Headers | ||
| * @return a reference to this, so the API can be used fluently | ||
| */ | ||
| static ProxyRequest reverseProxy(HttpServerRequest proxiedRequest, List<String> customHopHeaders) { | ||
| proxiedRequest.pause(); | ||
|
||
| return new ProxiedRequest(proxiedRequest, customHopHeaders); | ||
| } | ||
|
|
||
| /** | ||
| * @return the HTTP version of the proxied request | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a Set would be better here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, updated this. Used Set instead of List