Skip to content

Commit dac4013

Browse files
halfcrazydoujiang24
authored andcommitted
feature: implemented the new ngx.ssl.server_port() API to get server port.
1 parent fb1d4ab commit dac4013

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ install:
5656
- git clone https://github.com/openresty/mockeagain.git
5757
- git clone https://github.com/openresty/test-nginx.git
5858
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git
59-
- git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module
59+
- git clone -b feat/ssl-server-port https://github.com/halfcrazy/lua-nginx-module.git ../lua-nginx-module
6060
- git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module
6161
- git clone https://github.com/openresty/memc-nginx-module.git ../memc-nginx-module
6262
- git clone https://github.com/openresty/headers-more-nginx-module.git ../headers-more-nginx-module
6363
- git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache
64-
- git clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core
64+
- git clone -b feat/ssl-server-port https://github.com/halfcrazy/lua-resty-core.git ../lua-resty-core
6565

6666
script:
6767
- sudo iptables -I OUTPUT 1 -p udp --dport 10086 -j REJECT

src/ngx_stream_lua_ssl_certby.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,39 @@ ngx_stream_lua_ffi_ssl_server_name(ngx_stream_lua_request_t *r, char **name,
879879
}
880880

881881

882+
int
883+
ngx_stream_lua_ffi_ssl_server_port(ngx_stream_lua_request_t *r,
884+
unsigned short *server_port, char **err)
885+
{
886+
ngx_ssl_conn_t *ssl_conn;
887+
ngx_connection_t *c;
888+
889+
if (r->connection == NULL || r->connection->ssl == NULL) {
890+
*err = "bad request";
891+
return NGX_ERROR;
892+
}
893+
894+
ssl_conn = r->connection->ssl->connection;
895+
if (ssl_conn == NULL) {
896+
*err = "bad ssl conn";
897+
return NGX_ERROR;
898+
}
899+
900+
c = ngx_ssl_get_connection(ssl_conn);
901+
902+
switch (c->local_sockaddr->sa_family) {
903+
904+
case AF_UNIX:
905+
*err = "unix domain has no port";
906+
return NGX_ERROR;
907+
908+
default:
909+
*server_port = (unsigned short) ngx_inet_get_port(c->local_sockaddr);
910+
return NGX_OK;
911+
}
912+
}
913+
914+
882915
int
883916
ngx_stream_lua_ffi_ssl_raw_client_addr(ngx_stream_lua_request_t *r, char **addr,
884917
size_t *addrlen, int *addrtype, char **err)

0 commit comments

Comments
 (0)