Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
accesslog "github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3"
core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
grpc_web "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_web/v3"
router "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/router/v3"
tls_inspector "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/listener/tls_inspector/v3"
hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
Expand Down Expand Up @@ -92,15 +93,30 @@ func addXdsHTTPFilterChain(xdsListener *listener.Listener, irListener *ir.HTTPLi
}},
}

// Allow websocket upgrades for HTTP 1.1
// Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism
if !irListener.IsHTTP2 {
if irListener.IsHTTP2 {
Comment thread
zirain marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the godoc on IsHTTP2:

// IsHTTP2 is set if the upstream client as well as the downstream server are configured to serve HTTP2 traffic.

this is a little misleading i think? since the codec type is always set to "auto" and will infer the downstream protocol which could be HTTP/1 and upgraded when talking with the backend to gRPC now that this filter is applied

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should I configure it so that it can touch it ? @sunjayBhatia

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point @sunjayBhatia, we could limit IsHTTP2 to downstreams speaking HTTP/2, thereby limiting grpc-web for HTTP/2 only clients

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the PR with the codec type change from auto to http2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems useful for clients to be able to use gRPC-Web over HTTP/1 -> Envoy -> gRPC backend over HTTP/2 as well! but seems like that could be a separate feature if desired

// Set codec to HTTP2
mgr.CodecType = hcm.HttpConnectionManager_HTTP2

// Enable grpc-web filter for HTTP2
grpcWebAny, err := anypb.New(&grpc_web.GrpcWeb{})
if err != nil {
return err
}

grpcWebFilter := &hcm.HttpFilter{
Name: wellknown.GRPCWeb,
ConfigType: &hcm.HttpFilter_TypedConfig{TypedConfig: grpcWebAny},
}
// Ensure router is the last filter
mgr.HttpFilters = append([]*hcm.HttpFilter{grpcWebFilter}, mgr.HttpFilters...)
} else {
// Allow websocket upgrades for HTTP 1.1
// Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism
mgr.UpgradeConfigs = []*hcm.HttpConnectionManager_UpgradeConfig{
{
UpgradeType: "websocket",
},
}

}

// TODO: Make this a generic interface for all API Gateway features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
codecType: HTTP2
httpFilters:
- name: envoy.filters.http.grpc_web
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.grpc_web.v3.GrpcWeb
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
Expand Down