paivana

HTTP paywall reverse proxy
Log | Files | Refs | Submodules | README | LICENSE

commit b81e6292bdf764c9640888d8f9ed7836af2f122d
parent 7d499e344db4a9bbb6e3dedeea74769f32f966b2
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 31 May 2026 11:28:21 +0200

handle allocation failures better

Diffstat:
Msrc/backend/paivana-httpd_reverse.c | 73++++++++++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 40 insertions(+), 33 deletions(-)

diff --git a/src/backend/paivana-httpd_reverse.c b/src/backend/paivana-httpd_reverse.c @@ -667,46 +667,53 @@ curl_download_cb (void *cls, struct HttpRequest *hr = cls; hr->job = NULL; + if (GNUNET_YES == hr->suspended) + { + hr->suspended = GNUNET_NO; + MHD_resume_connection (hr->con); + TALER_MHD_daemon_trigger (); + } if (0 == response_code) { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to receive response from HTTP server\n"); hr->state = REQUEST_STATE_PROXY_DOWNLOAD_FAILED; + return; } - else + hr->response = MHD_create_response_from_buffer_copy (body_size, + body); + if (NULL == hr->response) { - hr->response = MHD_create_response_from_buffer_copy (body_size, - body); - GNUNET_assert (NULL != hr->response); - hr->response_code = response_code; - for (struct HttpResponseHeader *header = hr->header_head; - NULL != header; - header = header->next) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding MHD response header %s->%s\n", - header->type, - header->value); - GNUNET_break (MHD_YES == - MHD_add_response_header (hr->response, - header->type, - header->value)); - } - if ( (REQUEST_STATE_PROXY_DOWNLOAD_STARTED == hr->state) || - ( (REQUEST_STATE_PROXY_UPLOAD_STARTED == hr->state) && - (0 == hr->io_len) ) ) - { - /* Either the request body was empty (CURLOPT_POSTFIELDSIZE = 0, - so libcurl never called our read callback) or the upload - already drained but we have not yet entered upload_cb to - flip the state — either way, the upload is complete and we - can move straight on to consuming the response. */ - hr->state = REQUEST_STATE_PROXY_DOWNLOAD_DONE; - } + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Could not allocate memory for response of %llu bytes\n", + (unsigned long long) body_size); + hr->state = REQUEST_STATE_PROXY_DOWNLOAD_FAILED; + return; } - if (GNUNET_YES == hr->suspended) + hr->response_code = response_code; + for (struct HttpResponseHeader *header = hr->header_head; + NULL != header; + header = header->next) { - hr->suspended = GNUNET_NO; - MHD_resume_connection (hr->con); - TALER_MHD_daemon_trigger (); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Adding MHD response header %s->%s\n", + header->type, + header->value); + GNUNET_break (MHD_YES == + MHD_add_response_header (hr->response, + header->type, + header->value)); + } + if ( (REQUEST_STATE_PROXY_DOWNLOAD_STARTED == hr->state) || + ( (REQUEST_STATE_PROXY_UPLOAD_STARTED == hr->state) && + (0 == hr->io_len) ) ) + { + /* Either the request body was empty (CURLOPT_POSTFIELDSIZE = 0, + so libcurl never called our read callback) or the upload + already drained but we have not yet entered upload_cb to + flip the state — either way, the upload is complete and we + can move straight on to consuming the response. */ + hr->state = REQUEST_STATE_PROXY_DOWNLOAD_DONE; } }