Skip to content

Commit f354506

Browse files
authored
Add support for HTTP redirects and rewrites (#93)
* snake case file names * formatting fixes * HTTPRedirect and HTTPRewrite * route|redirect * remove oneof * comment nit
1 parent 3dcf956 commit f354506

File tree

1 file changed

+80
-11
lines changed

1 file changed

+80
-11
lines changed

proxy/v1/config/route_rule.proto

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,33 @@ message RouteRule {
9191
// traffic.
9292
MatchCondition match = 3;
9393

94-
// REQUIRED. Each routing rule is associated with one or more service
95-
// version destinations (see glossary in beginning of document). Weights
94+
// REQUIRED (route|redirect). A routing rule can either redirect traffic or
95+
// forward traffic. The forwarding target can be one of several versions
96+
// of a service (see glossary in beginning of document). Weights
9697
// associated with the service version determine the proportion of
9798
// traffic it receives.
9899
repeated DestinationWeight route = 4;
99100

101+
// REQUIRED (route|redirect). A routing rule can either redirect traffic or
102+
// forward traffic. The redirect primitive can be used to send a HTTP 302
103+
// redirect to a different URI or Authority.
104+
HTTPRedirect redirect = 5;
105+
106+
// Rewrite HTTP URIs and Authority headers. Rewrite cannot be used with
107+
// Redirect primitive. Rewrite will be performed before forwarding.
108+
HTTPRewrite rewrite = 6;
109+
100110
// Timeout policy for HTTP requests.
101-
HTTPTimeout http_req_timeout = 5;
111+
HTTPTimeout http_req_timeout = 7;
102112

103113
// Retry policy for HTTP requests.
104-
HTTPRetry http_req_retries = 6;
114+
HTTPRetry http_req_retries = 8;
105115

106116
//Fault injection policy to apply on HTTP traffic
107-
HTTPFaultInjection http_fault = 7;
117+
HTTPFaultInjection http_fault = 9;
108118

109119
//(-- L4 fault injection policy applies to Tcp/Udp (not HTTP) traffic --)
110-
L4FaultInjection l4_fault = 8 ;
120+
L4FaultInjection l4_fault = 10;
111121
}
112122

113123
// Match condition specifies a set of criterion to be met in order for the
@@ -149,11 +159,17 @@ message MatchCondition {
149159
L4MatchAttributes udp = 4 ;
150160

151161
// Set of HTTP match conditions based on HTTP/1.1, HTTP/2, GRPC request
152-
// metadata, such as "uri", "scheme", "authority". The header keys are
153-
// case-insensitive. *Note:* The key 'uri' carries a special meaning. It
154-
// can be used to perform URL matches. For URL matches ('uri' header),
155-
// only prefix and exact matches are supported. For other HTTP headers,
156-
// exact, prefix and ECMA style regular expression matches are supported.
162+
// metadata, such as _uri_, _scheme_, _authority_. The header keys are
163+
// case-insensitive.
164+
//
165+
// *Note 1:* The keys _uri_, _scheme_, _method_, and _authority_ correspond
166+
// to URI, protocol scheme (e.g., HTTP, HTTPS), HTTP method
167+
// (e.g., GET, POST), and the HTTP Host header respectively.
168+
//
169+
// *Note 2:* _uri_ can be used to perform URL matches. For URL matches
170+
// (_uri_), only prefix and exact (see StringMatch) matches are
171+
// supported. For other HTTP headers, exact, prefix and ECMA style
172+
// regular expression matches are supported.
157173
map<string, StringMatch> http_headers = 5;
158174
}
159175

@@ -205,6 +221,59 @@ message L4MatchAttributes {
205221
repeated string destination_subnet = 2;
206222
}
207223

224+
// HTTPRedirect can be used to send a 302 redirect response to the caller,
225+
// where the Authority/Host and the URI in the response can be swapped with
226+
// the specified values. For example, the following route rule redirects
227+
// requests for /v1/getProductRatings API on the ratings service to
228+
// /v1/bookRatings provided by the bookratings service.
229+
//
230+
// destination: ratings.default.svc.cluster.local
231+
// match:
232+
// httpHeaders:
233+
// uri:
234+
// exact: /v1/getProductRatings
235+
// redirect:
236+
// uri: /v1/bookRatings
237+
// authority: bookratings.default.svc.cluster.local
238+
//
239+
message HTTPRedirect {
240+
// On a redirect, overwrite the Path portion of the URL with this
241+
// value. Note that the entire path will be replaced, irrespective of the
242+
// request URI being matched as an exact path or prefix.
243+
string uri = 1;
244+
245+
// On a redirect, overwrite the Authority/Host portion of the URL with
246+
// this value
247+
string authority = 2;
248+
}
249+
250+
// HTTPRewrite can be used to rewrite specific parts of a HTTP request
251+
// before forwarding the request to the destination. Rewrite primitive can
252+
// be used only with the DestinationWeights. The following example
253+
// demonstrates how to rewrite the URL prefix for api call (/ratings) to
254+
// ratings service before making the actual API call.
255+
//
256+
// destination: ratings.default.svc.cluster.local
257+
// match:
258+
// httpHeaders:
259+
// uri:
260+
// prefix: /ratings
261+
// rewrite:
262+
// uri: /v1/bookRatings
263+
// route:
264+
// - tags:
265+
// version: v1
266+
//
267+
message HTTPRewrite {
268+
// rewrite the Path (or the prefix) portion of the URI with this
269+
// value. If the original URI was matched based on prefix, the value
270+
// provided in this field will replace the corresponding matched prefix.
271+
string uri = 1;
272+
273+
// rewrite the Authority/Host header with this value.
274+
string authority = 2;
275+
}
276+
208277
// Describes how to match a given string in HTTP headers. Match is case-sensitive.
209278
message StringMatch {
210279
oneof match_type {

0 commit comments

Comments
 (0)