Skip to content

Commit 2431d4b

Browse files
authored
fix missing put body (#23)
MINOR: added support for the HTTP PUT method This commit allows the program to mirror HTTP PUT requests. [mz: minor code revision and added note to documentation]
1 parent 2025ab2 commit 2431d4b

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

README

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ configuration file:
168168
HAProxy should be used in SSL termination mode if HTTPS is used in the HAProxy
169169
frontend part.
170170

171-
HTTP methods that certainly work are GET, HEAD and POST. Other methods can be
172-
added if necessary.
171+
HTTP methods that certainly work are GET, HEAD, POST and PUT. Other methods
172+
can be added if necessary. In order for the HTTP PUT method to work properly,
173+
it is necessary to add the 'option http-buffer-request' to the HAProxy
174+
configuration, because otherwise the contents of the HTTP body will not be
175+
transferred.
173176

src/.build-counter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2437
1+
2439

src/curl.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,50 @@ static CURLcode mir_curl_add_post(struct curl_con *con, const struct mirror *mir
784784
}
785785

786786

787+
/***
788+
* NAME
789+
* mir_curl_add_put -
790+
*
791+
* ARGUMENTS
792+
* con -
793+
* mir -
794+
*
795+
* DESCRIPTION
796+
* -
797+
*
798+
* RETURN VALUE
799+
* -
800+
*/
801+
static CURLcode mir_curl_add_put(struct curl_con *con, const struct mirror *mir)
802+
{
803+
CURLcode retval = CURLE_BAD_FUNCTION_ARGUMENT;
804+
805+
DBG_FUNC(NULL, "%p, %p", con, mir);
806+
807+
if (_NULL(con) || _NULL(mir))
808+
return retval;
809+
810+
if (mir->request_method != CURL_HTTP_METHOD_PUT)
811+
retval = CURLE_OK;
812+
else if ((retval = curl_easy_setopt(con->easy, CURLOPT_HTTP_CONTENT_DECODING, 0L)) != CURLE_OK)
813+
CURL_ERR_EASY("Failed to set HTTP content decoding", retval);
814+
else if ((retval = curl_easy_setopt(con->easy, CURLOPT_HTTP_TRANSFER_DECODING, 0L)) != CURLE_OK)
815+
CURL_ERR_EASY("Failed to set HTTP transfer decoding", retval);
816+
else if ((retval = curl_easy_setopt(con->easy, CURLOPT_READFUNCTION, mir_curl_read_cb)) != CURLE_OK)
817+
CURL_ERR_EASY("Failed to set read callback function", retval);
818+
else if ((retval = curl_easy_setopt(con->easy, CURLOPT_UPLOAD, 1L)) != CURLE_OK)
819+
CURL_ERR_EASY("Failed to enable uploading", retval);
820+
else if ((retval = curl_easy_setopt(con->easy, CURLOPT_PUT, 1L)) != CURLE_OK)
821+
CURL_ERR_EASY("Failed to init HTTP PUT data", retval);
822+
else if ((retval = curl_easy_setopt(con->easy, CURLOPT_READDATA, con)) != CURLE_OK)
823+
CURL_ERR_EASY("Failed to set read callback function data", retval);
824+
else if ((retval = curl_easy_setopt(con->easy, CURLOPT_INFILESIZE_LARGE, (curl_off_t)mir->body_size)) != CURLE_OK)
825+
CURL_ERR_EASY("Failed to set HTTP PUT data size", retval);
826+
827+
return retval;
828+
}
829+
830+
787831
/***
788832
* NAME
789833
* mir_curl_add_out -
@@ -979,7 +1023,9 @@ int mir_curl_add(struct curl_data *curl, struct mirror *mir)
9791023
CURL_ERR_EASY("Failed to set read timeout", rc);
9801024
else if ((rc = mir_curl_add_keepalive(con, 1, CURL_KEEPIDLE_TIME, CURL_KEEPINTVL_TIME)) != CURLE_OK)
9811025
/* Do nothing. */;
982-
else if ((rc = mir_curl_add_post(con, mir)) == CURLE_OK) {
1026+
else if ((rc = mir_curl_add_post(con, mir)) != CURLE_OK)
1027+
/* Do nothing. */;
1028+
else if ((rc = mir_curl_add_put(con, mir)) == CURLE_OK) {
9831029
CURL_DBG("Adding easy %p to multi %p (%s)", con->easy, curl->multi, mir->url);
9841030

9851031
con->curl = curl;

0 commit comments

Comments
 (0)