Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions lib/cache_rest.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ size_t buffer_write_callback(void *ptr, size_t size, size_t nmemb, void *data)
return mapcache_buffer_append(buffer, realsize, ptr);
}

static void _set_headers(mapcache_context *ctx, CURL *curl, apr_table_t *headers) {
static struct curl_slist* _set_headers(mapcache_context *ctx, CURL *curl, apr_table_t *headers) {
if(!headers) {
return;
return NULL;
} else {
struct curl_slist *curl_headers=NULL;
const apr_array_header_t *array = apr_table_elts(headers);
Expand All @@ -203,13 +203,15 @@ static void _set_headers(mapcache_context *ctx, CURL *curl, apr_table_t *headers
}
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers);
return curl_headers;
}
}

static void _put_request(mapcache_context *ctx, CURL *curl, mapcache_buffer *buffer, char *url, apr_table_t *headers) {
CURLcode res;
buffer_struct data;
mapcache_buffer *response;
struct curl_slist *curl_header_data;

data.buffer = buffer;
data.offset = 0;
Expand Down Expand Up @@ -238,7 +240,7 @@ static void _put_request(mapcache_context *ctx, CURL *curl, mapcache_buffer *buf

/* don't use an Expect: 100 Continue header */
apr_table_set(headers, "Expect", "");
_set_headers(ctx, curl, headers);
curl_header_data = _set_headers(ctx, curl, headers);

/* specify target URL, and note that this URL should include a file
* name, not only a directory */
Expand Down Expand Up @@ -272,14 +274,16 @@ static void _put_request(mapcache_context *ctx, CURL *curl, mapcache_buffer *buf
}
}

curl_slist_free_all(curl_header_data);
}

static int _head_request(mapcache_context *ctx, CURL *curl, char *url, apr_table_t *headers) {

CURLcode res;
long http_code;

_set_headers(ctx, curl, headers);
struct curl_slist *curl_header_data;

curl_header_data = _set_headers(ctx, curl, headers);

curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);

Expand All @@ -299,15 +303,18 @@ static int _head_request(mapcache_context *ctx, CURL *curl, char *url, apr_table
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
}

curl_slist_free_all(curl_header_data);

return (int)http_code;
}

static int _delete_request(mapcache_context *ctx, CURL *curl, char *url, apr_table_t *headers) {

CURLcode res;
long http_code;
struct curl_slist *curl_header_data;

_set_headers(ctx, curl, headers);
curl_header_data = _set_headers(ctx, curl, headers);

curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);

Expand All @@ -328,6 +335,8 @@ static int _delete_request(mapcache_context *ctx, CURL *curl, char *url, apr_tab
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
}

curl_slist_free_all(curl_header_data);

return (int)http_code;
}

Expand All @@ -336,8 +345,9 @@ static mapcache_buffer* _get_request(mapcache_context *ctx, CURL *curl, char *ur
CURLcode res;
mapcache_buffer *data = NULL;
long http_code;
struct curl_slist *curl_header_data;

_set_headers(ctx, curl, headers);
curl_header_data = _set_headers(ctx, curl, headers);

curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);

Expand Down Expand Up @@ -384,6 +394,8 @@ static mapcache_buffer* _get_request(mapcache_context *ctx, CURL *curl, char *ur
}
}

curl_slist_free_all(curl_header_data);

return data;
}

Expand Down Expand Up @@ -1019,7 +1031,7 @@ static int _mapcache_cache_rest_has_tile(mapcache_context *ctx, mapcache_cache *
int status;
mapcache_pooled_connection *pc;
CURL *curl;

_mapcache_cache_rest_tile_url(ctx, tile, &rcache->rest, &rcache->rest.has_tile, &url);
headers = _mapcache_cache_rest_headers(ctx, tile, &rcache->rest, &rcache->rest.has_tile);

Expand Down Expand Up @@ -1122,7 +1134,7 @@ static int _mapcache_cache_rest_get(mapcache_context *ctx, mapcache_cache *pcach
if(rcache->rest.get_tile.add_headers) {
rcache->rest.get_tile.add_headers(ctx,rcache,tile,url,headers);
}

pc = _rest_get_connection(ctx, rcache, tile);
if(GC_HAS_ERROR(ctx))
return MAPCACHE_FAILURE;
Expand Down Expand Up @@ -1250,7 +1262,7 @@ static void _mapcache_cache_rest_configuration_parse_xml(mapcache_context *ctx,
} else {
dcache->connection_timeout = 30;
}

if ((cur_node = ezxml_child(node,"timeout")) != NULL) {
char *endptr;
dcache->timeout = (int)strtol(cur_node->txt,&endptr,10);
Expand Down
9 changes: 5 additions & 4 deletions lib/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void mapcache_http_do_request(mapcache_context *ctx, mapcache_http *req, mapcach
ctx->set_error(ctx, 502, "curl failed to request url %s : %s", req->url, error_msg);
}
/* cleanup curl stuff */
curl_slist_free_all(curl_headers);
curl_easy_cleanup(curl_handle);
}

Expand All @@ -195,11 +196,11 @@ char to_hex(char code) {
char *url_encode(apr_pool_t *p, const char *str) {
char *buf = apr_pcalloc(p, strlen(str) * 3 + 1), *pbuf = buf;
while (*str) {
if (isalnum(*str) || *str == '-' || *str == '_' || *str == '.' || *str == '~')
if (isalnum(*str) || *str == '-' || *str == '_' || *str == '.' || *str == '~')
*pbuf++ = *str;
else if (*str == ' ')
else if (*str == ' ')
*pbuf++ = '+';
else
else
*pbuf++ = '%', *pbuf++ = to_hex(*str >> 4), *pbuf++ = to_hex(*str & 15);
str++;
}
Expand Down Expand Up @@ -388,7 +389,7 @@ mapcache_http* mapcache_http_configuration_parse_xml(mapcache_context *ctx, ezxm
} else {
req->connection_timeout = 30;
}

if ((http_node = ezxml_child(node,"timeout")) != NULL) {
char *endptr;
req->timeout = (int)strtol(http_node->txt,&endptr,10);
Expand Down