Add DirectResponseAction, a new route action type that returns a hard…#393
Add DirectResponseAction, a new route action type that returns a hard…#393mattklein123 merged 5 commits intoenvoyproxy:masterfrom brian-pane:direct-response/2315
Conversation
…-coded HTTP response. envoyproxy/envoy#2315 Signed-off-by: Brian Pane <bpane@pinterest.com>
api/rds.proto
Outdated
| RedirectAction redirect = 3; | ||
|
|
||
| // [#not-implemented-hide:] Return an arbitrary HTTP response directly, without proxying. | ||
| DirectResponseAction response = 7; |
There was a problem hiding this comment.
Name the field as direct_response. Since it has no wire cost, readability wins.
api/rds.proto
Outdated
|
|
||
| // Specifies the content of the response body. If this setting is omitted, | ||
| // no body is included in the generated response. | ||
| string body = 4; |
There was a problem hiding this comment.
You probably want to use a real HTTP response with headers and body.
There was a problem hiding this comment.
+1. I would probably remove content_type and just put in a repeated list of headers to add. You should be able to use existing header list messages in this file.
api/rds.proto
Outdated
|
|
||
| // Specifies the human-readable status to be returned if | ||
| // the response is encoded as HTTP/1.x. | ||
| string reason = 2; |
There was a problem hiding this comment.
Practically it's not going to be possible to actually use this. The HTTP/1.1 codec will select the reason based on the code for you and you can't set it. I would drop this.
api/rds.proto
Outdated
|
|
||
| // Specifies the content of the response body. If this setting is omitted, | ||
| // no body is included in the generated response. | ||
| string body = 4; |
There was a problem hiding this comment.
+1. I would probably remove content_type and just put in a repeated list of headers to add. You should be able to use existing header list messages in this file.
api/rds.proto
Outdated
|
|
||
| // Specifies the content of the response body. If this setting is omitted, | ||
| // no body is included in the generated response. | ||
| string body = 4; |
There was a problem hiding this comment.
I think this should be a DataSource, so that it can either be a file on disk, or provided inline.
There was a problem hiding this comment.
There's a practical problem with DataSource: its inline value is of type bytes, which will require people using JSON configs to base64-encode the value.
Do you have any objection to me extending DataSource to support a string option, to save JSON users the trouble of base64-encoding?
There was a problem hiding this comment.
@mattklein123 I don't understand. DataSource is already one_of ( bytes, filepath ). What are you wanting to make one_of? I think @brian-pane was asking if he can add another field to the existing one-of so it has (bytes, filepath, string).
If I'm understanding correctly, I have no objection to that, but I don't know if there's any negative protobuf side-effects, such as other uses of DataSource having to check for another value in the one-of.
If I'm not understanding correctly, can someone clarify for me?
There was a problem hiding this comment.
Yes, I'm proposing to add a string to the existing one_of.
There was a problem hiding this comment.
Sorry I didn't look at DataSource, so didn't know if it already had one_of. Yes, go for it! :)
There was a problem hiding this comment.
Yes, this is fine. BTW, I'm moving DataSource around to its own distinct file in #398.
There was a problem hiding this comment.
I'm happy to split out that part of the PR if it helps speed along this one.
…DataSource for body Signed-off-by: Brian Pane <bpane@pinterest.com>
api/base.proto
Outdated
| string filename = 1 [(validate.rules).string.min_bytes = 1]; | ||
|
|
||
| // Bytes inlined in the configuration. | ||
| bytes inline = 2 [(validate.rules).bytes.min_len = 1]; |
There was a problem hiding this comment.
Name this inline_bytes. We don't have a backwards compatibility requirement for field names; in general we avoid churn, but it's fine to do this where it is a win.
Signed-off-by: Brian Pane <bpane@pinterest.com>
api/rds.proto
Outdated
|
|
||
| message DirectResponseAction { | ||
| // Specifies the HTTP response status to be returned. | ||
| google.protobuf.UInt32Value status = 1 [(validate.rules).message.required = true]; |
There was a problem hiding this comment.
Can this be uint32 instead of google.protobuf.UInt32Value?
There was a problem hiding this comment.
Also, can we validate that it is >= 100 and < 600? (I don't know if that's even possible, but would be useful if it is)
There was a problem hiding this comment.
There's a precedent for using plain uint32 and range limits here:
https://github.com/envoyproxy/data-plane-api/blob/master/api/filter/http/fault.proto#L22
@htuch is that considered a good pattern to use? (I don't know the history behind why some declarations use the simple int types and others use the google.protobuf.* types.)
There was a problem hiding this comment.
This came up in the newly minted STYLE.md: https://github.com/envoyproxy/data-plane-api/blob/master/STYLE.md
"Use wrapped scalar types where there is a real need for the field to have a default value that does not match the proto3 default (0/false/""). This should not be done for fields where the proto3 defaults make sense. All things being equal, pick appropriate logic, e.g. enable vs. disable for a bool field, such that the proto3 defaults work, but only where this doesn't result in API gymnastics."
There was a problem hiding this comment.
Yep, +1 to @ggreenway comment above, we've been getting better at using unwrapped scalar types where it makes sense, so go for it.
…alidator Signed-off-by: Brian Pane <bpane@pinterest.com>
api/rds.proto
Outdated
| uint32 status = 1 [(validate.rules).uint32 = {gte: 100, lt: 600}]; | ||
|
|
||
| // Specifies headers to include in the HTTP response. | ||
| repeated HeaderValue response_headers = 2; |
There was a problem hiding this comment.
It occurs to me that we already have response_headers_to_add on the route. Do we need this?
There was a problem hiding this comment.
If that's sufficient I might delete this and just put a comment in on body with a ref link to the other field and see it can be used for setting headers.
Signed-off-by: Brian Pane <bpane@pinterest.com>
…-coded HTTP response.
envoyproxy/envoy#2315
Signed-off-by: Brian Pane bpane@pinterest.com