Skip to content

Commit

Permalink
http_client: http_query reuse the default user agent setting
Browse files Browse the repository at this point in the history
- based on GH #674, by Jurijs Ivolga
- useful for simplified upgrade of the configs using utils version of
  the http query to the http_client module
  • Loading branch information
miconda committed Jul 4, 2016
1 parent 4949ebb commit 875fd4c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/http_client/functions.c
Expand Up @@ -54,6 +54,7 @@ typedef struct {
char *ciphersuites;
char *http_proxy;
char *failovercon;
char *useragent;
unsigned int authmethod;
unsigned int http_proxy_port;
unsigned int tlsversion;
Expand All @@ -68,11 +69,11 @@ typedef struct {
} curl_query_t;


/*
/*
* curl write function that saves received data as zero terminated
* to stream. Returns the amount of data taken care of.
*
* This function may be called multiple times for larger responses,
* This function may be called multiple times for larger responses,
* so it reallocs + concatenates the buffer as needed.
*/
size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr)
Expand Down Expand Up @@ -228,6 +229,8 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst, const
res |= curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
res |= curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);

if(params->useragent)
res |= curl_easy_setopt(curl, CURLOPT_USERAGENT, params->useragent);

if (res != CURLE_OK) {
/* PANIC */
Expand Down Expand Up @@ -587,6 +590,9 @@ int http_query(struct sip_msg* _m, char* _url, str* _dst, char* _post)
query_params.http_follow_redirect = default_http_follow_redirect;
query_params.oneline = 1;
query_params.maxdatasize = 0;
if(default_useragent.s!=NULL && default_useragent.len>0) {
query_params.useragent = default_useragent.s;
}
if(default_http_proxy.s!=NULL && default_http_proxy.len>0) {
query_params.http_proxy = default_http_proxy.s;
if(default_http_proxy_port>0) {
Expand Down

0 comments on commit 875fd4c

Please sign in to comment.