Skip to content

Commit

Permalink
adjust weight default value and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokai-wang committed Nov 30, 2015
1 parent af92e86 commit b681c1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ or

* adjust-weight
```
curl -X PUT -d '{\"weight\":2}' http://$consul_ip:$port/v1/kv/$dir1/$upstream_name/$backend_ip:$backend_port
curl -X PUT -d "{\"weight\":2}" http://$consul_ip:$port/v1/kv/$dir1/$upstream_name/$backend_ip:$backend_port
```

* check
Expand Down
28 changes: 16 additions & 12 deletions src/ngx_http_dynamic_update_upstream_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1535,39 +1535,43 @@ ngx_http_dynamic_update_upstream_parse_json(u_char *buf,
cJSON *temp1 = cJSON_GetObjectItem(sub_attribute, "weight");
if (temp1 != NULL) {

if (temp1->valueint >= 0) {
upstream_conf->weight = temp1->valueint;
} else if (temp1->valuestring != NULL) {

if (temp1->valuestring != NULL) {
upstream_conf->weight = ngx_atoi((u_char *)temp1->valuestring,
(size_t)ngx_strlen(temp1->valuestring));

} else if (temp1->valueint >= 0) {
upstream_conf->weight = temp1->valueint;
}

}
temp1 = NULL;

temp1 = cJSON_GetObjectItem(sub_attribute, "max_fails");
if (temp1 != NULL) {

if (temp1->valueint >= 0) {
max_fails = temp1->valueint;
} else if (temp1->valuestring != NULL) {

if (temp1->valuestring != NULL) {
max_fails = ngx_atoi((u_char *)temp1->valuestring,
(size_t)ngx_strlen(temp1->valuestring));

} else if (temp1->valueint >= 0) {
max_fails = temp1->valueint;
}

}
temp1 = NULL;

temp1 = cJSON_GetObjectItem(sub_attribute, "fail_timeout");
if (temp1 != NULL){

if (temp1->valueint >= 0) {
upstream_conf->fail_timeout = temp1->valueint;
} else if (temp1->valuestring != NULL) {
if (temp1->valuestring != NULL) {

upstream_conf->fail_timeout = ngx_atoi((u_char *)temp1->valuestring,
(size_t)ngx_strlen(temp1->valuestring));

} else if (temp1->valueint >= 0) {
upstream_conf->fail_timeout = temp1->valueint;
}

}
temp1 = NULL;

Expand Down Expand Up @@ -1601,7 +1605,7 @@ ngx_http_dynamic_update_upstream_parse_json(u_char *buf,
cJSON_Delete(sub_root);
}

if (upstream_conf->weight < 0) {
if (upstream_conf->weight <= 0) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
"dynamic_update_upstream_parse_json: \"weight\" value is invalid and seting to 1");
upstream_conf->weight = 1;
Expand Down

0 comments on commit b681c1c

Please sign in to comment.