Title: [BUG] Final keys without values are not processed for POST body · Issue #268 · etr/libhttpserver · GitHub
Open Graph Title: [BUG] Final keys without values are not processed for POST body · Issue #268 · etr/libhttpserver
X Title: [BUG] Final keys without values are not processed for POST body · Issue #268 · etr/libhttpserver
Description: Prerequisites Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo:etr/libhttpserver&type=Issues Description For a POST or PUT request with body forma...
Open Graph Description: Prerequisites Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo:etr/libhttpserver&type=Issues Description F...
X Description: Prerequisites Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo:etr/libhttpserver&type=Issues D...
Opengraph URL: https://github.com/etr/libhttpserver/issues/268
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG] Final keys without values are not processed for POST body","articleBody":"### Prerequisites\r\n\r\n* [x] Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=\u0026q=repo%3Aetr%2Flibhttpserver\u0026type=Issues\r\n\r\n### Description\r\n\r\nFor a POST or PUT request with body format `application/x-www-form-urlencoded`, if there are final parameters with `key`, but without `value` these are left unprocessed and not being reported as arguments in the request.\r\n\r\n### Steps to Reproduce\r\n\r\n1 . Compile and launch this little code snippet:\r\n```\r\n#include \u003cnumeric\u003e\r\n#include \u003cstring\u003e\r\n#include \u003cutility\u003e\r\n\r\n#include \"httpserver.hpp\"\r\n\r\nusing std::string;\r\nusing std::pair;\r\n\r\nusing namespace httpserver;\r\n\r\nclass hello_world_resource : public http_resource {\r\npublic:\r\n const std::shared_ptr\u003chttp_response\u003e render(const http_request\u0026 req) {\r\n const auto\u0026 args = req.get_args();\r\n string recv_args = std::accumulate(args.begin(), args.end(), string {},\r\n [] (string\u0026 res, const pair\u003cstring,string\u003e\u0026 arg) -\u003e string {\r\n const string key_val_str { \"\\\"\" + arg.first + \"\\\": \" + \"'\" + arg.second + \"'\" };\r\n\r\n if (res.empty()) {\r\n res = key_val_str;\r\n } else {\r\n res = res + \", \" + key_val_str;\r\n }\r\n\r\n return res;\r\n }\r\n );\r\n\r\n return std::shared_ptr\u003chttp_response\u003e(new string_response(\"Received args: {\" + recv_args + \"}\"));\r\n }\r\n};\r\n\r\nint main(int argc, char** argv) {\r\n webserver ws = create_webserver(8080);\r\n\r\n hello_world_resource hwr;\r\n ws.register_resource(\"/hello\", \u0026hwr);\r\n ws.start(true);\r\n \r\n return 0;\r\n}\r\n```\r\n\r\n2. Perform the following requests to the registered endpoint.\r\n\r\n* curl --insecure -d \"arg1=\" -H \"Content-Type: application/x-www-form-urlencoded\" -X POST \"http://127.0.0.1:8080/hello\"\r\n* curl --insecure -d \"arg1=\u0026arg2=\" -H \"Content-Type: application/x-www-form-urlencoded\" -X POST \"http://127.0.0.1:8080/hello\"\r\n\r\n**Expected behavior:**\r\n\r\n* Response for first request **should be**: `Received args: {arg1=''}`\r\n* Response for second request **should be**: `Received args: {arg1='', arg2=''}`\r\n\r\n**Actual behavior:**\r\n\r\n* Response for first request **is**: `Received args: {}`\r\n* Response for second request **is**: `Received args: {arg1=''}`\r\n\r\n**Reproduces how often:** 100%\r\n\r\n### Versions\r\n\r\n* OS version: Linux 5.17.5-arch1-2\r\n* libhttpserver version: `master` compiled and 0.18.1 compiled\r\n* libmicrohttpd version: libmicrohttpd-0.9.68 compiled\r\n\r\n### Additional Information\r\n\r\nI'm submitting a PR with the potential fix.\r\n","author":{"url":"https://github.com/JavierJF","@type":"Person","name":"JavierJF"},"datePublished":"2022-05-13T15:23:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/268/libhttpserver/issues/268"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:02498f53-925e-8255-c4bd-41fab341ebf4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D618:134C26:9DAAB1:D5EE4B:696AB8AD |
| html-safe-nonce | df0b40bc9d3a87afaefc2e2f722852c63772e3f601b26e856a2536a6fc2a05dc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjE4OjEzNEMyNjo5REFBQjE6RDVFRTRCOjY5NkFCOEFEIiwidmlzaXRvcl9pZCI6IjEwNzA2Nzg5MjEzODEwNjY5MjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 77dca2137931d6bf6401b7b5cea501b4ee8c98c35f505b8c16676ff75275c66e |
| hovercard-subject-tag | issue:1235387508 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/etr/libhttpserver/268/issue_layout |
| twitter:image | https://opengraph.githubassets.com/64ddf067e06be30a626d657490ee0a21824f781ba0a925a42db32b4298f5ea2f/etr/libhttpserver/issues/268 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/64ddf067e06be30a626d657490ee0a21824f781ba0a925a42db32b4298f5ea2f/etr/libhttpserver/issues/268 |
| og:image:alt | Prerequisites Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo:etr/libhttpserver&type=Issues Description F... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JavierJF |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4fa1799b6a53c2d30c950d74230781bef9e7f61138c72c7727e4b83f0743752b |
| turbo-cache-control | no-preview |
| go-import | github.com/etr/libhttpserver git https://github.com/etr/libhttpserver.git |
| octolytics-dimension-user_id | 1201536 |
| octolytics-dimension-user_login | etr |
| octolytics-dimension-repository_id | 3416891 |
| octolytics-dimension-repository_nwo | etr/libhttpserver |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3416891 |
| octolytics-dimension-repository_network_root_nwo | etr/libhttpserver |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 41f276818bd204c4a30a0281fb3c576298d9474c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width