|
| 1 | +diff --git a/bundle/lua-resty-core-0.1.28/lib/ngx/balancer.lua b/bundle/lua-resty-core-0.1.28/lib/ngx/balancer.lua |
| 2 | +index 7d64d63..b0b7543 100644 |
| 3 | +--- a/bundle/lua-resty-core-0.1.28/lib/ngx/balancer.lua |
| 4 | ++++ b/bundle/lua-resty-core-0.1.28/lib/ngx/balancer.lua |
| 5 | +@@ -22,6 +22,7 @@ local ngx_lua_ffi_balancer_set_current_peer |
| 6 | + local ngx_lua_ffi_balancer_set_more_tries |
| 7 | + local ngx_lua_ffi_balancer_get_last_failure |
| 8 | + local ngx_lua_ffi_balancer_set_timeouts -- used by both stream and http |
| 9 | ++local ngx_lua_ffi_balancer_set_upstream_tls |
| 10 | + |
| 11 | + |
| 12 | + if subsystem == 'http' then |
| 13 | +@@ -41,6 +42,8 @@ if subsystem == 'http' then |
| 14 | + |
| 15 | + int ngx_http_lua_ffi_balancer_recreate_request(ngx_http_request_t *r, |
| 16 | + char **err); |
| 17 | ++ int ngx_http_lua_ffi_balancer_set_upstream_tls(ngx_http_request_t *r, |
| 18 | ++ int on, char **err); |
| 19 | + ]] |
| 20 | + |
| 21 | + ngx_lua_ffi_balancer_set_current_peer = |
| 22 | +@@ -55,6 +58,9 @@ if subsystem == 'http' then |
| 23 | + ngx_lua_ffi_balancer_set_timeouts = |
| 24 | + C.ngx_http_lua_ffi_balancer_set_timeouts |
| 25 | + |
| 26 | ++ ngx_lua_ffi_balancer_set_upstream_tls = |
| 27 | ++ C.ngx_http_lua_ffi_balancer_set_upstream_tls |
| 28 | ++ |
| 29 | + elseif subsystem == 'stream' then |
| 30 | + ffi.cdef[[ |
| 31 | + int ngx_stream_lua_ffi_balancer_set_current_peer( |
| 32 | +@@ -228,6 +234,29 @@ if subsystem == 'http' then |
| 33 | + |
| 34 | + return nil, "failed to recreate the upstream request" |
| 35 | + end |
| 36 | ++ |
| 37 | ++ |
| 38 | ++ function _M.set_upstream_tls(on) |
| 39 | ++ local r = get_request() |
| 40 | ++ if not r then |
| 41 | ++ return error("no request found") |
| 42 | ++ end |
| 43 | ++ |
| 44 | ++ local rc |
| 45 | ++ |
| 46 | ++ if on == 0 or on == false then |
| 47 | ++ on = 0 |
| 48 | ++ else |
| 49 | ++ on = 1 |
| 50 | ++ end |
| 51 | ++ |
| 52 | ++ rc = ngx_lua_ffi_balancer_set_upstream_tls(r, on, errmsg); |
| 53 | ++ if rc == FFI_OK then |
| 54 | ++ return true |
| 55 | ++ end |
| 56 | ++ |
| 57 | ++ return nil, ffi_str(errmsg[0]) |
| 58 | ++ end |
| 59 | + end |
| 60 | + |
| 61 | + |
| 62 | +diff --git a/bundle/lua-resty-core-0.1.28/lib/ngx/balancer.md b/bundle/lua-resty-core-0.1.28/lib/ngx/balancer.md |
| 63 | +index ef2f124..3ec8cb9 100644 |
| 64 | +--- a/bundle/lua-resty-core-0.1.28/lib/ngx/balancer.md |
| 65 | ++++ b/bundle/lua-resty-core-0.1.28/lib/ngx/balancer.md |
| 66 | +@@ -13,11 +13,12 @@ Table of Contents |
| 67 | + * [stream subsystem](#stream-subsystem) |
| 68 | + * [Description](#description) |
| 69 | + * [Methods](#methods) |
| 70 | ++ * [get_last_failure](#get_last_failure) |
| 71 | ++ * [recreate_request](#recreate_request) |
| 72 | + * [set_current_peer](#set_current_peer) |
| 73 | + * [set_more_tries](#set_more_tries) |
| 74 | +- * [get_last_failure](#get_last_failure) |
| 75 | + * [set_timeouts](#set_timeouts) |
| 76 | +- * [recreate_request](#recreate_request) |
| 77 | ++ * [set_upstream_tls](#set_upstream_tls) |
| 78 | + * [Community](#community) |
| 79 | + * [English Mailing List](#english-mailing-list) |
| 80 | + * [Chinese Mailing List](#chinese-mailing-list) |
| 81 | +@@ -270,6 +271,21 @@ This function was first added in the `0.1.20` version of this library. |
| 82 | + |
| 83 | + [Back to TOC](#table-of-contents) |
| 84 | + |
| 85 | ++set_upstream_tls |
| 86 | ++------------ |
| 87 | ++**syntax:** `ok, err = balancer.set_upstream_tls(on)` |
| 88 | ++ |
| 89 | ++**context:** *balancer_by_lua** |
| 90 | ++ |
| 91 | ++Turn off the HTTPs or reenable the HTTPs for the upstream connection. |
| 92 | ++ |
| 93 | ++- If `on` is `true`, then the https protocol will be used to connect to the upstream server. |
| 94 | ++- If `on` is `false`, then the http protocol will be used to connect to the upstream server. |
| 95 | ++ |
| 96 | ++This function was first added in the `0.1.29` version of this library. |
| 97 | ++ |
| 98 | ++[Back to TOC](#table-of-contents) |
| 99 | ++ |
| 100 | + Community |
| 101 | + ========= |
| 102 | + |
| 103 | +diff --git a/bundle/lua-resty-core-0.1.28/t/balancer.t b/bundle/lua-resty-core-0.1.28/t/balancer.t |
| 104 | +index 3e9fb2f..6201b47 100644 |
| 105 | +--- a/bundle/lua-resty-core-0.1.28/t/balancer.t |
| 106 | ++++ b/bundle/lua-resty-core-0.1.28/t/balancer.t |
| 107 | +@@ -882,3 +882,98 @@ connect() failed (111: Connection refused) while connecting to upstream, client: |
| 108 | + --- no_error_log |
| 109 | + [warn] |
| 110 | + [crit] |
| 111 | ++ |
| 112 | ++ |
| 113 | ++ |
| 114 | ++=== TEST 20: set_upstream_tls off |
| 115 | ++--- skip_nginx: 5: < 1.7.5 |
| 116 | ++--- http_config |
| 117 | ++ lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; |
| 118 | ++ |
| 119 | ++ upstream backend { |
| 120 | ++ server 0.0.0.1; |
| 121 | ++ balancer_by_lua_block { |
| 122 | ++ local b = require "ngx.balancer" |
| 123 | ++ b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port)) |
| 124 | ++ b.set_upstream_tls(false) |
| 125 | ++ } |
| 126 | ++ keepalive 1; |
| 127 | ++ } |
| 128 | ++ |
| 129 | ++ server { |
| 130 | ++ listen $TEST_NGINX_RAND_PORT_1 ssl; |
| 131 | ++ ssl_certificate ../../cert/test.crt; |
| 132 | ++ ssl_certificate_key ../../cert/test.key; |
| 133 | ++ |
| 134 | ++ server_tokens off; |
| 135 | ++ location = /back { |
| 136 | ++ return 200 "ok"; |
| 137 | ++ } |
| 138 | ++ } |
| 139 | ++--- config |
| 140 | ++ location /t { |
| 141 | ++ proxy_pass https://backend/back; |
| 142 | ++ proxy_http_version 1.1; |
| 143 | ++ proxy_set_header Connection ""; |
| 144 | ++ } |
| 145 | ++ |
| 146 | ++ location /back { |
| 147 | ++ echo "Hello world!"; |
| 148 | ++ } |
| 149 | ++--- request |
| 150 | ++ GET /t |
| 151 | ++--- no_error_log |
| 152 | ++[alert] |
| 153 | ++[error] |
| 154 | ++--- response_body |
| 155 | ++Hello world! |
| 156 | ++ |
| 157 | ++--- no_check_leak |
| 158 | ++ |
| 159 | ++ |
| 160 | ++ |
| 161 | ++=== TEST 21: set_upstream_tls on |
| 162 | ++--- skip_nginx: 5: < 1.7.5 |
| 163 | ++--- http_config |
| 164 | ++ lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; |
| 165 | ++ |
| 166 | ++ upstream backend { |
| 167 | ++ server 0.0.0.1; |
| 168 | ++ balancer_by_lua_block { |
| 169 | ++ local b = require "ngx.balancer" |
| 170 | ++ b.set_current_peer("127.0.0.1", $TEST_NGINX_RAND_PORT_1) |
| 171 | ++ b.set_upstream_tls(false) |
| 172 | ++ b.set_upstream_tls(true) |
| 173 | ++ } |
| 174 | ++ |
| 175 | ++ keepalive 1; |
| 176 | ++ } |
| 177 | ++ |
| 178 | ++ server { |
| 179 | ++ listen $TEST_NGINX_RAND_PORT_1 ssl; |
| 180 | ++ ssl_certificate ../../cert/test.crt; |
| 181 | ++ ssl_certificate_key ../../cert/test.key; |
| 182 | ++ |
| 183 | ++ server_tokens off; |
| 184 | ++ location = /back { |
| 185 | ++ return 200 "ok"; |
| 186 | ++ } |
| 187 | ++ } |
| 188 | ++--- config |
| 189 | ++ location /t { |
| 190 | ++ proxy_pass https://backend/back; |
| 191 | ++ proxy_http_version 1.1; |
| 192 | ++ proxy_set_header Connection ""; |
| 193 | ++ } |
| 194 | ++ |
| 195 | ++ location /back { |
| 196 | ++ echo "Hello world!"; |
| 197 | ++ } |
| 198 | ++--- request |
| 199 | ++ GET /t |
| 200 | ++--- no_error_log |
| 201 | ++[alert] |
| 202 | ++[error] |
| 203 | ++--- response_body chomp |
| 204 | ++ok |
| 205 | ++--- no_check_leak |
0 commit comments