Skip to content

Commit

Permalink
add http_status check when nginx startup
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokai-wang committed Apr 8, 2017
1 parent 1f93cf5 commit 57ad7a4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/ngx_stream_upsync_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2702,6 +2702,11 @@ ngx_stream_upsync_consul_parse_init(void *data)

parsed = http_parser_execute(parser, &settings, buf, ngx_strlen(buf));
if (parsed != ngx_strlen(buf)) {

if (parser != NULL) {
ngx_free(parser);
parser = NULL;
}
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
"upsync_consul_parse_init: parsed body size is wrong");
return NGX_ERROR;
Expand Down Expand Up @@ -2752,6 +2757,11 @@ ngx_stream_upsync_etcd_parse_init(void *data)

parsed = http_parser_execute(parser, &settings, buf, ngx_strlen(buf));
if (parsed != ngx_strlen(buf)) {

if (parser != NULL) {
ngx_free(parser);
parser = NULL;
}
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
"upsync_etcd_parse_init: parsed body size is wrong");
return NGX_ERROR;
Expand Down Expand Up @@ -3387,7 +3397,6 @@ ngx_stream_upsync_get_upstream(ngx_cycle_t *cycle,
char *response = NULL;

ngx_stream_client_send(client, upsync_server);

if (ngx_stream_client_recv(client, &response, 0) <= 0) {
ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
"upsync_get_upstream: http client recv fail");
Expand All @@ -3400,9 +3409,20 @@ ngx_stream_upsync_get_upstream(ngx_cycle_t *cycle,

return NGX_ERROR;
}

ngx_stream_client_destroy(client);

if (ngx_stream_http_parser_init() == NGX_ERROR) {
return NGX_ERROR;
}
http_parser_execute(parser, &settings, response, ngx_strlen(response));
if (parser != NULL) {
ngx_free(parser);
parser = NULL;
}
if (ngx_strncmp(state.status, "OK", 2) != 0) {
return NGX_ERROR;
}

*conf_value = response;

return NGX_OK;
Expand Down

0 comments on commit 57ad7a4

Please sign in to comment.