Add support for the X-Reject-Reason extension
This commit is contained in:
parent
364051e8f3
commit
8d7a870479
2 changed files with 20 additions and 8 deletions
|
@ -323,6 +323,14 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
|
||||||
s,
|
s,
|
||||||
json_is_true(res) ? "(yay!!!)" : "(booooo)");
|
json_is_true(res) ? "(yay!!!)" : "(booooo)");
|
||||||
|
|
||||||
|
if (opt_debug) {
|
||||||
|
json_t *tmp;
|
||||||
|
const char *reason;
|
||||||
|
tmp = json_object_get(val, "reject-reason");
|
||||||
|
if (tmp && (reason = json_string_value(tmp)))
|
||||||
|
applog(LOG_DEBUG, "DEBUG: reject reason: %s", reason);
|
||||||
|
}
|
||||||
|
|
||||||
json_decref(val);
|
json_decref(val);
|
||||||
|
|
||||||
rc = true;
|
rc = true;
|
||||||
|
|
20
util.c
20
util.c
|
@ -46,6 +46,7 @@ struct upload_buffer {
|
||||||
|
|
||||||
struct header_info {
|
struct header_info {
|
||||||
char *lp_path;
|
char *lp_path;
|
||||||
|
char *reason;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tq_ent {
|
struct tq_ent {
|
||||||
|
@ -224,14 +225,16 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data)
|
||||||
if (!*val) /* skip blank value */
|
if (!*val) /* skip blank value */
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (opt_protocol)
|
|
||||||
applog(LOG_DEBUG, "HTTP hdr(%s): %s", key, val);
|
|
||||||
|
|
||||||
if (!strcasecmp("X-Long-Polling", key)) {
|
if (!strcasecmp("X-Long-Polling", key)) {
|
||||||
hi->lp_path = val; /* steal memory reference */
|
hi->lp_path = val; /* steal memory reference */
|
||||||
val = NULL;
|
val = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcasecmp("X-Reject-Reason", key)) {
|
||||||
|
hi->reason = val; /* steal memory reference */
|
||||||
|
val = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(key);
|
free(key);
|
||||||
free(val);
|
free(val);
|
||||||
|
@ -318,10 +321,8 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
||||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str);
|
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str);
|
||||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
|
||||||
if (lp_scanning) {
|
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb);
|
||||||
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb);
|
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);
|
||||||
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);
|
|
||||||
}
|
|
||||||
if (opt_proxy) {
|
if (opt_proxy) {
|
||||||
curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy);
|
curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy);
|
||||||
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type);
|
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type);
|
||||||
|
@ -366,7 +367,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If X-Long-Polling was found, activate long polling */
|
/* If X-Long-Polling was found, activate long polling */
|
||||||
if (hi.lp_path) {
|
if (lp_scanning && hi.lp_path) {
|
||||||
have_longpoll = true;
|
have_longpoll = true;
|
||||||
tq_push(thr_info[longpoll_thr_id].q, hi.lp_path);
|
tq_push(thr_info[longpoll_thr_id].q, hi.lp_path);
|
||||||
} else
|
} else
|
||||||
|
@ -415,6 +416,9 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hi.reason)
|
||||||
|
json_object_set_new(val, "reject-reason", json_string(hi.reason));
|
||||||
|
|
||||||
databuf_free(&all_data);
|
databuf_free(&all_data);
|
||||||
curl_slist_free_all(headers);
|
curl_slist_free_all(headers);
|
||||||
curl_easy_reset(curl);
|
curl_easy_reset(curl);
|
||||||
|
|
Loading…
Reference in a new issue