commit b6b7f4616e7c933b3ed4520c64e8d281fb17f8d7
parent b32820ae40c155b3c89b0b01cdd4c06b967880c6
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 8 Mar 2018 15:01:16 +0100
fix proxied response headers.
Diffstat:
1 file changed, 34 insertions(+), 28 deletions(-)
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c
@@ -132,6 +132,11 @@ struct HttpRequest
char *io_buf;
/**
+ * Hold the response obtained by modifying the original one.
+ */
+ struct MHD_Response *mod_response;
+
+ /**
* MHD response object for this request.
*/
struct MHD_Response *response;
@@ -1066,15 +1071,13 @@ create_response (void *cls,
"Still waiting for response to be ready\n");
return MHD_YES;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing response with MHD\n");
if (0 != hack_response_code)
{
hr->response_code = hack_response_code;
hack_response_code = 0; /* reset for next request */
}
- /* Empty the object pointed by `delete_path` only if
+ /* Empty the object pointed by `delete_path` ONLY IF
it is found within this response, otherwise it leaves
the response untouched. */
if ('\0' != delete_path[0])
@@ -1084,14 +1087,8 @@ create_response (void *cls,
json_t *cur;
json_error_t error;
char *token_path;
- char *mod_response;
+ char *mod_body;
unsigned int index;
- /* XXX: Who destroys the unused response? */
-
- if (NULL == MHD_lookup_connection_value
- (con, MHD_HEADER_KIND, "application/json"))
- /* No JSON header, but will try to parse it anyway. */
- TALER_LOG_WARNING ("Response is not JSON (?)\n");
if (NULL == (parsed_response = json_loadb
(hr->io_buf, hr->io_len, JSON_DECODE_ANY, &error)))
@@ -1155,25 +1152,29 @@ create_response (void *cls,
hr->response);
}
- TALER_LOG_INFO ("Emptying object '%s'\n",
- json_dumps (element, JSON_COMPACT));
- mod_response = json_dumps (parsed_response, JSON_COMPACT);
-
- json_decref (parsed_response);
-
- /* We only reset once a empty-able object has
- been found. This way, it is possible to call this
- API way in advance respect to the response which
- is to be transformed. */
- delete_path[0] = '\0';
- json_decref (parsed_response);
- return MHD_queue_response
- (con, hr->response_code,
- MHD_create_response_from_buffer (strlen (mod_response),
- mod_response,
- MHD_RESPMEM_MUST_COPY));
+ mod_body = json_dumps (parsed_response, JSON_COMPACT);
+
+ hr->mod_response = MHD_create_response_from_buffer
+ (strlen (mod_body),
+ mod_body,
+ MHD_RESPMEM_MUST_COPY);
+ json_decref (parsed_response);
+ delete_path[0] = '\0';
+
+ struct HttpResponseHeader *header;
+ for (header = hr->header_head;
+ NULL != header;
+ header = header->next)
+ GNUNET_break
+ (MHD_YES == MHD_add_response_header (hr->mod_response,
+ header->type,
+ header->value));
+ return MHD_queue_response (con,
+ hr->response_code,
+ hr->mod_response);
}
- /* Response is untouched. */
+
+ /* response might have been modified. */
return MHD_queue_response (con,
hr->response_code,
hr->response);
@@ -1223,6 +1224,11 @@ mhd_completed_cb (void *cls,
hr->curl = NULL;
hr->io_len = 0;
}
+
+ if ((NULL != hr->mod_response))
+ /* Destroy hacked responses. */
+ MHD_destroy_response (hr->mod_response);
+
if ( (NULL != hr->response) &&
(curl_failure_response != hr->response) )
/* Destroy non-error responses... (?) */