-
Notifications
You must be signed in to change notification settings - Fork 170
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
Feature: Add HTTP2 support. #1128
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
argparse 0.6.0-1||production | ||
busted 2.0.rc12-1||testing | ||
basexx 0.4.1-1||development | ||
binaryheap 0.4-1||development | ||
bit32 5.3.0-1||development | ||
compat53 0.7-1||development | ||
cqueues 20190813.51-0||development | ||
dkjson 2.5-2||testing | ||
fifo 0.2-0||development | ||
http 0.3-0||development | ||
inspect 3.1.1-0||production | ||
ldoc 1.4.6-2||development | ||
liquid 0.1.3-1||production | ||
ljsonschema 0.1.0-1||testing | ||
lpeg 1.0.2-1||development | ||
lpeg_patterns 0.5-0||development | ||
lua-resty-env 0.4.0-1||production | ||
lua-resty-execvp 0.1.1-1||production | ||
lua-resty-http 0.12-0||production | ||
lua-resty-http 0.15-0||production | ||
lua-resty-iputils 0.3.0-1||production | ||
lua-resty-jit-uuid 0.0.7-1||production | ||
lua-resty-jit-uuid 0.0.7-2||production | ||
lua-resty-jwt 0.2.0-0||production | ||
lua-resty-repl 0.0.6-0||development | ||
lua-resty-repl 0.0.6-0|3878f41b7e8f97b1c96919db19dbee9496569dda|development | ||
lua-resty-url 0.3.5-1||production | ||
lua-term 0.7-1||testing | ||
lua_cliargs 3.0-1||testing | ||
lua_cliargs 3.0-2||testing | ||
luacov 0.13.0-1||testing | ||
luafilesystem 1.7.0-2||production,development,testing | ||
luassert 1.7.10-0||testing | ||
luaossl 20190731-0||development | ||
luassert 1.8.0-0||testing | ||
luasystem 0.2.1-0||testing | ||
lyaml 6.2.3-1||production | ||
lyaml 6.2.4-1||production | ||
markdown 0.33-1||development | ||
mediator_lua 1.1.2-0||testing | ||
net-url 0.9-1||testing | ||
nginx-lua-prometheus 0.20171117-4||production | ||
penlight 1.5.4-1||production,development,testing | ||
nginx-lua-prometheus 0.20181120-2||production | ||
penlight 1.7.0-1||production,development,testing | ||
router 2.1-0||production | ||
say 1.3-1||testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
location @grpc_upstream { | ||
|
||
internal; | ||
|
||
rewrite_by_lua_block { | ||
require('resty.ctx').apply() | ||
} | ||
|
||
grpc_pass grpcs://upstream; | ||
|
||
|
||
grpc_set_header X-Real-IP $remote_addr; | ||
grpc_set_header Host $http_host; | ||
grpc_set_header X-3scale-grpc-secret-token $secret_token; | ||
grpc_set_header X-3scale-debug ""; | ||
grpc_set_header Connection ""; | ||
|
||
# This is a bit tricky. It uses liquid to set a SSL client certificate. In | ||
# NGINX, all this is not executed as it is commented with '#'. However, in | ||
# Liquid, all this will be evaluated. As a result, the following directives | ||
# are set optionally: grpc_ssl_certificate, grpc_ssl_certificate_key, | ||
# grpc_ssl_session_reuse, and grpc_ssl_password_file. | ||
|
||
# {% if proxy_ssl_certificate != empty and proxy_ssl_certificate_key != empty %} | ||
# {% capture proxy_ssl %} | ||
#{#} grpc_ssl_certificate {{ proxy_ssl_certificate }}; | ||
#{#} grpc_ssl_certificate_key {{ proxy_ssl_certificate_key }}; | ||
# {% endcapture %} | ||
# {{ proxy_ssl | replace: "#{#}", "" }} | ||
# | ||
# {% if proxy_ssl_password_file != empty %} | ||
# {% capture proxy_ssl %} | ||
#{#} grpc_ssl_password_file {{ proxy_ssl_password_file }}; | ||
# {% endcapture %} | ||
# {{ proxy_ssl | replace: "#{#}", "" }} | ||
# {% endif %} | ||
# | ||
# {% if proxy_ssl_session_reuse != empty %} | ||
# {% capture proxy_ssl %} | ||
#{#} grpc_ssl_session_reuse {{ proxy_ssl_session_reuse }}; | ||
# {% endcapture %} | ||
# {{ proxy_ssl | replace: "#{#}", "" }} | ||
# {% endif %} | ||
# {% endif %} | ||
|
||
# When 'upstream_retry_cases' is empty, apply the same default as NGINX. | ||
# If the proxy_next_upstream directive is not declared, the retry policy | ||
# will never retry. | ||
# {% if upstream_retry_cases != empty %} | ||
# {% capture proxy_next_upstream %} | ||
#{#} grpc_next_upstream {{ upstream_retry_cases }}; | ||
# {% endcapture %} | ||
# {{ proxy_next_upstream | replace: "#{#}", "" }} | ||
# {% else %} | ||
# grpc_next_upstream error timeout; | ||
# {% endif %} | ||
# these are duplicated so when request is redirected here those phases are executed | ||
|
||
post_action @out_of_band_authrep_action; | ||
body_filter_by_lua_block { require('apicast.executor'):body_filter() } | ||
header_filter_by_lua_block { require('apicast.executor'):header_filter() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "http://apicast.io/policy-v1.1/schema#manifest#", | ||
"name": "HTTP2 endpoint", | ||
eloycoto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"summary": "Main functionality to enable HTTP2 endpoint reply.", | ||
"description": | ||
["To enable full HTTP2 traffic from the user to the final endpoint "], | ||
"version": "builtin", | ||
"configuration": { | ||
"type": "object", | ||
"properties": { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
-- This policy enables HTTP2 handle on the API endpoint. | ||
|
||
local policy = require('apicast.policy') | ||
local _M = policy.new('grpc', "builtin") | ||
local resty_url = require('resty.url') | ||
local round_robin = require 'resty.balancer.round_robin' | ||
|
||
local new = _M.new | ||
|
||
local balancer = round_robin.new() | ||
|
||
function _M.new(config) | ||
local self = new(config) | ||
return self | ||
end | ||
|
||
function _M:rewrite(context) | ||
if ngx.var.server_protocol == "HTTP/2.0" then | ||
-- upstream defined in gateway/conf.d/http2.conf | ||
context.upstream_location_name = "@grpc_upstream" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment that references the file where this location is defined? |
||
end | ||
end | ||
|
||
function _M:balancer(context) | ||
if not context.upstream_location_name then | ||
return | ||
end | ||
|
||
-- balancer need to be used due to grpc_pass does not support variables and | ||
-- upstream block need to be in place. | ||
local upstream = context:get_upstream() | ||
if not upstream then | ||
ngx.log(ngx.WARN, "Upstream is not present in the balancer") | ||
return | ||
end | ||
|
||
local peers = balancer:peers(upstream.servers) | ||
local peer, err = balancer:select_peer(peers) | ||
if err then | ||
ngx.log(ngx.WARN, "Cannot get a peer for the given upstream", err) | ||
return | ||
end | ||
|
||
local ip = peer[1] | ||
local port = peer[2] or upstream.uri.port or resty_url.default_port(upstream.uri.scheme) | ||
local _, err = balancer:set_current_peer(ip, port) | ||
|
||
if err then | ||
ngx.log(ngx.WARN, "Cannot set balancer IP and port '", ip, ":", port, "'") | ||
return | ||
end | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
return require('grpc') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be good to evaluate whether this change has any impact on performance.
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.
It's using lua coroutines and it's the recommended way in Openresty, it's safe to update.