|
| 1 | +#include <ngx_stream.h> |
| 2 | +#include <ngx_stream_lua_api.h> |
| 3 | +#include "ngx_stream_apisix_module.h" |
| 4 | + |
| 5 | + |
| 6 | +typedef struct { |
| 7 | + unsigned proxy_ssl_enabled:1; |
| 8 | +} ngx_stream_apisix_ctx_t; |
| 9 | + |
| 10 | + |
| 11 | +static ngx_stream_module_t ngx_stream_apisix_module_ctx = { |
| 12 | + NULL, /* preconfiguration */ |
| 13 | + NULL, /* postconfiguration */ |
| 14 | + |
| 15 | + NULL, /* create main configuration */ |
| 16 | + NULL, /* init main configuration */ |
| 17 | + |
| 18 | + NULL, /* create server configuration */ |
| 19 | + NULL, /* merge server configuration */ |
| 20 | +}; |
| 21 | + |
| 22 | + |
| 23 | +ngx_module_t ngx_stream_apisix_module = { |
| 24 | + NGX_MODULE_V1, |
| 25 | + &ngx_stream_apisix_module_ctx, /* module context */ |
| 26 | + NULL, /* module directives */ |
| 27 | + NGX_STREAM_MODULE, /* module type */ |
| 28 | + NULL, /* init master */ |
| 29 | + NULL, /* init module */ |
| 30 | + NULL, /* init process */ |
| 31 | + NULL, /* init thread */ |
| 32 | + NULL, /* exit thread */ |
| 33 | + NULL, /* exit process */ |
| 34 | + NULL, /* exit master */ |
| 35 | + NGX_MODULE_V1_PADDING |
| 36 | +}; |
| 37 | + |
| 38 | + |
| 39 | +ngx_int_t |
| 40 | +ngx_stream_apisix_upstream_enable_tls(ngx_stream_lua_request_t *r) |
| 41 | +{ |
| 42 | + ngx_stream_apisix_ctx_t *ctx; |
| 43 | + |
| 44 | + ctx = ngx_stream_lua_get_module_ctx(r, ngx_stream_apisix_module); |
| 45 | + if (ctx == NULL) { |
| 46 | + ctx = ngx_pcalloc(r->pool, sizeof(ngx_stream_apisix_ctx_t)); |
| 47 | + if (ctx == NULL) { |
| 48 | + return NGX_ERROR; |
| 49 | + } |
| 50 | + |
| 51 | + ngx_stream_lua_set_ctx(r, ctx, ngx_stream_apisix_module); |
| 52 | + } |
| 53 | + |
| 54 | + ctx->proxy_ssl_enabled = 1; |
| 55 | + |
| 56 | + return NGX_OK; |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +ngx_int_t |
| 61 | +ngx_stream_apisix_is_proxy_ssl_enabled(ngx_stream_session_t *s) |
| 62 | +{ |
| 63 | + ngx_stream_apisix_ctx_t *ctx; |
| 64 | + |
| 65 | + ctx = ngx_stream_get_module_ctx(s, ngx_stream_apisix_module); |
| 66 | + |
| 67 | + return ctx != NULL && ctx->proxy_ssl_enabled; |
| 68 | +} |
0 commit comments