-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathProxyRequest.java
More file actions
198 lines (175 loc) · 5.51 KB
/
ProxyRequest.java
File metadata and controls
198 lines (175 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Copyright (c) 2011-2020 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.httpproxy;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Future;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.net.HostAndPort;
import io.vertx.httpproxy.impl.ProxiedRequest;
import java.util.Set;
/**
*
* Handles the interoperability of the <b>request</b> between the <i><b>user agent</b></i> and the <i><b>origin</b></i>.
*
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
@VertxGen
public interface ProxyRequest {
/**
* Create a new {@code ProxyRequest} instance, the proxied request will be paused.
*
* @param proxiedRequest the {@code HttpServerRequest} that is proxied
* @return a reference to this, so the API can be used fluently
*/
static ProxyRequest reverseProxy(HttpServerRequest proxiedRequest) {
proxiedRequest.pause();
return new ProxiedRequest(proxiedRequest);
}
/**
* @return the HTTP version of the proxied request
*/
HttpVersion version();
/**
* @return the absolute URI of the proxied request
*/
String absoluteURI();
/**
* @return the HTTP method to be sent to the <i><b>origin</b></i> server.
*/
HttpMethod getMethod();
/**
* Set the HTTP method to be sent to the <i><b>origin</b></i> server.
*
* <p>The initial HTTP method value is the proxied request HTTP method.
*
* @param method the new HTTP method
* @return a reference to this, so the API can be used fluently
*/
@Fluent
ProxyRequest setMethod(HttpMethod method);
/**
* @return the request URI to be sent to the <i><b>origin</b></i> server.
*/
String getURI();
/**
* Set the request URI to be sent to the <i><b>origin</b></i> server.
*
* <p>The initial request URI value is the proxied request URI.
*
* @param uri the new URI
* @return a reference to this, so the API can be used fluently
*/
@Fluent
ProxyRequest setURI(String uri);
/**
* @return the request body to be sent to the <i><b>origin</b></i> server.
*/
Body getBody();
/**
* Set the request body to be sent to the <i><b>origin</b></i> server.
*
* <p>The initial request body value is the proxied request body.
*
* @param body the new body
* @return a reference to this, so the API can be used fluently
*/
@Fluent
ProxyRequest setBody(Body body);
/**
* Set the request authority.
*
* <ul>
* <li>for HTTP/1 the {@literal Host} header</li>
* <li>for HTTP/2 the {@literal :authority} pseudo header</li>
* </ul>
*
* The value must follow the {@literal <host>:<port>} syntax.
*
* @param authority the authority
* @return a reference to this, so the API can be used fluently
*/
@Fluent
ProxyRequest setAuthority(HostAndPort authority);
/**
* @return the request authority, for HTTP2 the {@literal :authority} pseudo header otherwise the {@literal Host} header
*/
HostAndPort getAuthority();
/**
* @return the headers that will be sent to the origin server, the returned headers can be modified. The headers
* map is populated with the proxied request headers
*/
MultiMap headers();
/**
* Put an HTTP header.
*
* @param name The header name
* @param value The header value
* @return a reference to this, so the API can be used fluently
*/
@GenIgnore
@Fluent
ProxyRequest putHeader(CharSequence name, CharSequence value);
/**
* Proxy this request to the <i><b>origin</b></i> server using the specified {@code request} and then send the proxy response.
*
* @param request the request connected to the <i><b>origin</b></i> server
*/
default Future<Void> proxy(HttpClientRequest request) {
return send(request).flatMap(resp -> resp.send());
}
/**
* Send this request to the <i><b>origin</b></i> server using the specified {@code request}.
*
* <p> The returned future will be completed with the proxy response returned by the <i><b>origin</b></i>.
*
* @param request the request connected to the <i><b>origin</b></i> server
*/
Future<ProxyResponse> send(HttpClientRequest request);
/**
* Release the proxy request and its associated resources.
*
* <p> The HTTP server request is resumed, no HTTP server response is sent.
*
* @return a reference to this, so the API can be used fluently
*/
@Fluent
ProxyRequest release();
/**
* @return the proxied HTTP server request
*/
HttpServerRequest proxiedRequest();
/**
* Create and return the proxy response.
*
* @return the proxy response
*/
ProxyResponse response();
/**
* Set Custom Hop-By-Hop Headers
*
* @return a reference to this, so the API can be used fluently
*/
@Fluent
ProxyRequest setCustomHopHeaders(Set<String> customHopHeaders);
/**
* Add Custom Hop-By-Hop Header
*
* @return a reference to this, so the API can be used fluently
*/
@Fluent
ProxyRequest addCustomHopHeader(String customHopHeader);
}