View Issue Details

IDProjectCategoryView StatusLast Update
0006068libmicrohttpdotherpublic2021-09-02 15:54
Reporterclennon Assigned ToChristian Grothoff Due Date
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformLinuxOSCentOSOS Version7
Product Version0.9.69 
Target Version0.9.70Fixed in Version0.9.70 
Summary0006068: No response using PATCH method with data
DescriptionI'm using the following to send a response to a HTTP request:

#define FORBIDDEN "{\"error_text\": \"Permission Denied\"}"
struct MHD_Response *response=NULL;
response = MHD_create_response_from_buffer(strlen (FORBIDDEN),
                                           (void *) FORBIDDEN,
                                           MHD_RESPMEM_PERSISTENT);
MHD_add_response_header(response, "Content-Type", "application/json");
ret = MHD_queue_response (connection, MHD_HTTP_FORBIDDEN, response);
MHD_destroy_response (response);

For a PUT request with data, the client is getting the response.

However, with a PATCH request with data, the client is not getting a response.

Looking at the MHD_connection_handle_idle function src/microhttpd/connection.c I can see that the POST and PUT methods are
handled differently to everything else (e.g. when the state is MHD_CONNECTION_HEADERS_PROCESSED)
TagsNo tags attached.
Attached Files

Activities

clennon

2020-01-29 14:47

reporter   ~0015302

git diff that fixes this
libmicrohttpd_PATCH.patch (1,195 bytes)   
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 52f57ae..e5eb7ab 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3412,6 +3412,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
            ( (MHD_str_equal_caseless_ (connection->method,
                                        MHD_HTTP_METHOD_POST)) ||
              (MHD_str_equal_caseless_ (connection->method,
+                                       MHD_HTTP_METHOD_PATCH)) ||
+             (MHD_str_equal_caseless_ (connection->method,
                                        MHD_HTTP_METHOD_PUT))) )
       {
         /* we refused (no upload allowed!) */
@@ -4041,6 +4043,8 @@ MHD_queue_response (struct MHD_Connection *connection,
        ( (MHD_str_equal_caseless_ (connection->method,
                                    MHD_HTTP_METHOD_POST)) ||
          (MHD_str_equal_caseless_ (connection->method,
+                                   MHD_HTTP_METHOD_PATCH)) ||
+         (MHD_str_equal_caseless_ (connection->method,
                                    MHD_HTTP_METHOD_PUT))) )
   {
     /* response was queued "early", refuse to read body / footers or

libmicrohttpd_PATCH.patch (1,195 bytes)   

Christian Grothoff

2020-02-07 22:50

manager   ~0015316

Well, while I'd like to support this for PATCH, the proposed diff is not nice. Basically, the problem is that this style will require us to add each method to the list, and there are potentially many more. Instead, we should probably simply test for the client having sent '100 continue' *and* headers indicative that a body may follow. Then the 100 continue logic should run. And if there is no upload, then the application should queue the final reply immediately anyway.

Christian Grothoff

2020-02-08 15:52

manager   ~0015317

44c32e4c..78d0fb7b should fix this properly. I would appreciate it if you could quickly test it and report back.

Christian Grothoff

2020-02-08 20:59

manager   ~0015322

Reporter confirmed this fixes the issue.

Christian Grothoff

2021-09-02 15:54

manager   ~0018169

Fix committed to master branch.

Issue History

Date ModifiedUsernameFieldChange
2020-01-29 11:38clennonNew Issue
2020-01-29 14:47clennonFile Added: libmicrohttpd_PATCH.patch
2020-01-29 14:47clennonNote Added: 0015302
2020-02-07 13:16Christian GrothoffAssigned To => Christian Grothoff
2020-02-07 13:16Christian GrothoffStatusnew => assigned
2020-02-07 22:50Christian GrothoffNote Added: 0015316
2020-02-07 22:50Christian GrothoffTarget Version => 0.9.70
2020-02-08 15:52Christian GrothoffNote Added: 0015317
2020-02-08 15:52Christian GrothoffAssigned ToChristian Grothoff =>
2020-02-08 15:52Christian GrothoffStatusassigned => feedback
2020-02-08 20:59Christian GrothoffAssigned To => Christian Grothoff
2020-02-08 20:59Christian GrothoffStatusfeedback => resolved
2020-02-08 20:59Christian GrothoffResolutionopen => fixed
2020-02-08 20:59Christian GrothoffFixed in Version => 0.9.70
2020-02-08 20:59Christian GrothoffNote Added: 0015322
2020-02-08 21:03Christian GrothoffStatusresolved => closed
2021-09-02 15:54Christian Grothoff
2021-09-02 15:54Christian GrothoffNote Added: 0018169