Add User-Agent header to each HTTP request

This commit is contained in:
Jeff Garzik 2011-03-22 13:58:32 -04:00 committed by Jeff Garzik
parent 46819af36f
commit a7d9f31747

4
util.c
View file

@ -203,7 +203,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
struct upload_buffer upload_data; struct upload_buffer upload_data;
json_error_t err = { }; json_error_t err = { };
struct curl_slist *headers = NULL; struct curl_slist *headers = NULL;
char len_hdr[64]; char len_hdr[64], user_agent_hdr[128];
char curl_err_str[CURL_ERROR_SIZE]; char curl_err_str[CURL_ERROR_SIZE];
long timeout = longpoll ? (60 * 60) : (60 * 10); long timeout = longpoll ? (60 * 60) : (60 * 10);
struct header_info hi = { }; struct header_info hi = { };
@ -244,10 +244,12 @@ json_t *json_rpc_call(CURL *curl, const char *url,
upload_data.len = strlen(rpc_req); upload_data.len = strlen(rpc_req);
sprintf(len_hdr, "Content-Length: %lu", sprintf(len_hdr, "Content-Length: %lu",
(unsigned long) upload_data.len); (unsigned long) upload_data.len);
sprintf(user_agent_hdr, "User-Agent: %s", PACKAGE_STRING);
headers = curl_slist_append(headers, headers = curl_slist_append(headers,
"Content-type: application/json"); "Content-type: application/json");
headers = curl_slist_append(headers, len_hdr); headers = curl_slist_append(headers, len_hdr);
headers = curl_slist_append(headers, user_agent_hdr);
headers = curl_slist_append(headers, "Expect:"); /* disable Expect hdr*/ headers = curl_slist_append(headers, "Expect:"); /* disable Expect hdr*/
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);