Skip to content

Commit

Permalink
Merge pull request #1299 from jinjiu/master
Browse files Browse the repository at this point in the history
Add new variables: $ssl_handshake_time and $ssl_handshake_time_msec and fix handshake time bug.
  • Loading branch information
mrpre authored Jun 26, 2019
2 parents cae4b1c + 6a8fa79 commit 362a8fc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/event/ngx_event_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5448,7 +5448,7 @@ ngx_ssl_get_handshake_time(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
tp = ngx_timeofday();

if (c->ssl->handshake_end_msec == 0) {
ms = tp->sec * 1000 + tp->sec - c->ssl->handshake_start_msec;
ms = tp->sec * 1000 + tp->msec - c->ssl->handshake_start_msec;

} else {
ms = c->ssl->handshake_end_msec - c->ssl->handshake_start_msec;
Expand All @@ -5461,6 +5461,42 @@ ngx_ssl_get_handshake_time(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
return NGX_ERROR;
}

s->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p;
s->data = p;

return NGX_OK;
}


ngx_int_t
ngx_ssl_get_handshake_time_msec(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
{
ngx_msec_int_t ms;
u_char *p;
ngx_time_t *tp;

if (c->ssl == NULL) {
ngx_str_null(s);

return NGX_OK;
}

tp = ngx_timeofday();

if (c->ssl->handshake_end_msec == 0) {
ms = tp->sec * 1000 + tp->msec - c->ssl->handshake_start_msec;

} else {
ms = c->ssl->handshake_end_msec - c->ssl->handshake_start_msec;
}

ms = ngx_max(ms, 0);

p = ngx_pnalloc(pool, NGX_TIME_T_LEN);
if (p == NULL) {
return NGX_ERROR;
}

s->len = ngx_sprintf(p, "%i", ms) - p;
s->data = p;

Expand Down
2 changes: 2 additions & 0 deletions src/event/ngx_event_openssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ ngx_int_t ngx_ssl_get_client_v_remain(ngx_connection_t *c, ngx_pool_t *pool,
#if (T_NGX_SSL_HANDSHAKE_TIME)
ngx_int_t ngx_ssl_get_handshake_time(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
ngx_int_t ngx_ssl_get_handshake_time_msec(ngx_connection_t *c, ngx_pool_t *pool,
ngx_str_t *s);
#endif


Expand Down
7 changes: 7 additions & 0 deletions src/http/modules/ngx_http_ssl_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,15 @@ static ngx_http_variable_t ngx_http_ssl_vars[] = {
(uintptr_t) ngx_ssl_get_client_v_remain, NGX_HTTP_VAR_CHANGEABLE, 0 },

#if (T_NGX_SSL_HANDSHAKE_TIME)
/* $ssl_shandshakd_time deprecated and will be removed in the next release */
{ ngx_string("ssl_handshakd_time"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_handshake_time, NGX_HTTP_VAR_CHANGEABLE, 0 },

{ ngx_string("ssl_handshake_time"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_handshake_time, NGX_HTTP_VAR_CHANGEABLE, 0 },

{ ngx_string("ssl_handshake_time_msec"), NULL, ngx_http_ssl_variable,
(uintptr_t) ngx_ssl_get_handshake_time_msec, NGX_HTTP_VAR_CHANGEABLE, 0 },
#endif

ngx_http_null_variable
Expand Down
7 changes: 7 additions & 0 deletions src/stream/ngx_stream_ssl_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,15 @@ static ngx_stream_variable_t ngx_stream_ssl_vars[] = {
(uintptr_t) ngx_ssl_get_client_v_remain, NGX_STREAM_VAR_CHANGEABLE, 0 },

#if (T_NGX_SSL_HANDSHAKE_TIME)
/* $ssl_shandshakd_time deprecated and will be removed in the next release */
{ ngx_string("ssl_handshakd_time"), NULL, ngx_stream_ssl_variable,
(uintptr_t) ngx_ssl_get_handshake_time, NGX_STREAM_VAR_CHANGEABLE, 0 },

{ ngx_string("ssl_handshake_time"), NULL, ngx_stream_ssl_variable,
(uintptr_t) ngx_ssl_get_handshake_time, NGX_STREAM_VAR_CHANGEABLE, 0 },

{ ngx_string("ssl_handshake_time_msec"), NULL, ngx_stream_ssl_variable,
(uintptr_t) ngx_ssl_get_handshake_time_msec, NGX_STREAM_VAR_CHANGEABLE, 0 },
#endif

ngx_stream_null_variable
Expand Down

0 comments on commit 362a8fc

Please sign in to comment.