summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-12-19 23:41:03 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-12-19 23:41:03 +0100
commitcd970073d9f23ffd90766d500e10702414533f0d (patch)
tree89c9c575a03a4da697d695bd82014693f058d9c6
parent396b7747db0d1ba94f1cd3369f826c2c779ed454 (diff)
downloadtwister-cd970073d9f23ffd90766d500e10702414533f0d.tar.gz
twister-cd970073d9f23ffd90766d500e10702414533f0d.tar.bz2
twister-cd970073d9f23ffd90766d500e10702414533f0d.zip
Minor changes.
Logs messages, 'deflate' flag, response header parsing fixes.
-rw-r--r--src/twister/taler-twister-service.c109
1 files changed, 69 insertions, 40 deletions
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c
index 0b18768..6670d51 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -220,6 +220,11 @@ struct HttpRequest
*/
int curl_paused;
+ /**
+ * if GNUNET_YES, then request and response will carry
+ * a compressed body.
+ */
+ int deflate;
};
@@ -374,11 +379,17 @@ curl_check_hdr (void *buffer,
char *hdr_val;
char *tok;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking headers..\n");
+ /* Raw line is not guaranteed to be null-terminated. */
+ ndup = GNUNET_malloc (bytes + 1);
+ memcpy (ndup,
+ buffer,
+ bytes);
+ ndup[bytes] = '\0';
- ndup = GNUNET_strndup (buffer, bytes);
+ TALER_LOG_DEBUG ("Raw line: '%s'\n",
+ ndup);
hdr_type = strtok (ndup, ":");
+
if (NULL == hdr_type)
{
GNUNET_free (ndup);
@@ -393,6 +404,27 @@ curl_check_hdr (void *buffer,
if (' ' == *hdr_val)
hdr_val++;
+ /* MHD does not allow certain characters in values,
+ * remove those, plus those could alter strings matching. */
+ if (NULL != (tok = strchr (hdr_val, '\n')))
+ *tok = '\0';
+ if (NULL != (tok = strchr (hdr_val, '\r')))
+ *tok = '\0';
+ if (NULL != (tok = strchr (hdr_val, '\t')))
+ *tok = '\0';
+
+ TALER_LOG_DEBUG ("Parsed line: '%s: %s'\n",
+ hdr_type,
+ hdr_val);
+
+ if (0 == strcasecmp (hdr_type,
+ MHD_HTTP_HEADER_CONTENT_ENCODING))
+ {
+ TALER_LOG_WARNING ("Artificially skipping 'C-E'\n");
+ GNUNET_free (ndup);
+ return bytes;
+ }
+
/* Skip "Host:" header as it will be wrong, given
that we are man-in-the-middling the connection */
if (0 == strcasecmp (hdr_type,
@@ -410,21 +442,8 @@ curl_check_hdr (void *buffer,
return bytes;
}
- /* MHD does not allow certain characters in values,
- * remove those */
- if (NULL != (tok = strchr (hdr_val, '\n')))
- *tok = '\0';
- if (NULL != (tok = strchr (hdr_val, '\r')))
- *tok = '\0';
- if (NULL != (tok = strchr (hdr_val, '\t')))
- *tok = '\0';
-
if (0 != strlen (hdr_val)) /* Rely in MHD to set those */
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding header %s: %s to MHD response\n",
- hdr_type,
- hdr_val);
header = GNUNET_new (struct HttpResponseHeader);
header->type = GNUNET_strdup (hdr_type);
header->value = GNUNET_strdup (hdr_val);
@@ -800,7 +819,7 @@ curl_task_download (void *cls)
if (NULL == hr->response)
hr->response = curl_failure_response;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Curl request for `%s' finished, response generated\n",
+ "Curl request for `%s' finished (got the response)\n",
hr->url);
run_mhd_now ();
break;
@@ -833,7 +852,7 @@ curl_task_download (void *cls)
}
-/* *************** MHD response generation ******************* */
+/* *************** MHD response generation ***************** */
/**
@@ -858,9 +877,18 @@ con_val_iter (void *cls,
(void) kind;
- if ((0 == strcmp ("Accept-Encoding", key))
- && (0 == strcmp ("deflate", value)))
- return MHD_YES;
+ if ((0 == strcmp (MHD_HTTP_HEADER_ACCEPT_ENCODING,
+ key))
+ && (0 == strcmp ("deflate",
+ value)))
+ {
+ hr->deflate = GNUNET_YES;
+ TALER_LOG_INFO ("Compressed request\n");
+ curl_easy_setopt (hr->curl,
+ CURLOPT_ENCODING,
+ "deflate");
+ return MHD_YES;
+ }
if (GNUNET_YES == malform_upload)
{
@@ -873,13 +901,13 @@ con_val_iter (void *cls,
malform_upload = GNUNET_NO;
}
}
-
GNUNET_asprintf (&hdr,
"%s: %s",
key,
value);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding HEADER `%s' to HTTP request\n",
+ "Adding header `%s' to HTTP request\n",
hdr);
hr->headers = curl_slist_append (hr->headers,
hdr);
@@ -1378,32 +1406,32 @@ create_response (void *cls,
}
if (0 != hr->io_len)
curl_easy_setopt (hr->curl,
- CURLOPT_POSTFIELDSIZE,
- hr->io_len);
+ CURLOPT_POSTFIELDSIZE,
+ hr->io_len);
curl_easy_setopt (hr->curl,
CURLOPT_HEADERFUNCTION,
&curl_check_hdr);
curl_easy_setopt (hr->curl,
- CURLOPT_HEADERDATA,
- hr);
+ CURLOPT_HEADERDATA,
+ hr);
curl_easy_setopt (hr->curl,
- CURLOPT_FOLLOWLOCATION,
- 0);
+ CURLOPT_FOLLOWLOCATION,
+ 0);
curl_easy_setopt (hr->curl,
- CURLOPT_CONNECTTIMEOUT,
- 600L);
+ CURLOPT_CONNECTTIMEOUT,
+ 600L);
curl_easy_setopt (hr->curl,
- CURLOPT_TIMEOUT,
- 600L);
+ CURLOPT_TIMEOUT,
+ 600L);
curl_easy_setopt (hr->curl,
- CURLOPT_NOSIGNAL,
- 1L);
+ CURLOPT_NOSIGNAL,
+ 1L);
curl_easy_setopt (hr->curl,
- CURLOPT_PRIVATE,
- hr);
+ CURLOPT_PRIVATE,
+ hr);
curl_easy_setopt (hr->curl,
- CURLOPT_VERBOSE,
- 0);
+ CURLOPT_VERBOSE,
+ 0);
{
char *curlurl;
@@ -1581,6 +1609,7 @@ create_response (void *cls,
MHD_HEADER_KIND,
&con_val_iter,
hr);
+
curl_easy_setopt (hr->curl,
CURLOPT_HTTPHEADER,
hr->headers);
@@ -1746,7 +1775,7 @@ mhd_completed_cb (void *cls,
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished request for %s\n",
+ "Proxying of '%s' completely done\n",
hr->url);
GNUNET_free (hr->url);