Title: [BUG] Query parameters missing in get_args() result if path arguments are used. · Issue #342 · etr/libhttpserver · GitHub
Open Graph Title: [BUG] Query parameters missing in get_args() result if path arguments are used. · Issue #342 · etr/libhttpserver
X Title: [BUG] Query parameters missing in get_args() result if path arguments are used. · Issue #342 · 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 The result from calling http_request::get...
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 T...
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/342
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG] Query parameters missing in get_args() result if path arguments are used.","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\nThe result from calling `http_request::get_args()` will not contain URL query parameters if the resource URL has path parameters. This is due to `webserver::finalize_answer(...)` calling `http_server::set_arg(...)` for each URL path argument, thus rendering `http_request::cache::unescaped_args` non-empty. `http_request::get_args()` will call `http_request::populate_args()`, which will do nothing if `unescaped_args` is non-empty.\r\n\r\n### Steps to Reproduce\r\n\r\n1. Change line `examples/hello_with_get_arg.cpp:26` from\r\n```\r\nreturn std::shared_ptr\u003chttpserver::http_response\u003e(new httpserver::string_response(\"Hello: \" + std::string(req.get_arg(\"name\"))));\r\n```\r\nto\r\n```\r\nreturn std::shared_ptr\u003chttpserver::http_response\u003e(new httpserver::string_response(std::string(req.get_arg(\"greeting\")) + \", \" + std::string(req.get_arg(\"name\"))));\r\n```\r\n2. Change line `examples/hello_with_get_arg.cpp:34` from\r\n```\r\nws.register_resource(\"/hello\", \u0026hwr);\r\n```\r\nto lines\r\n```\r\nhwr.disallow_all();\r\nhwr.set_allowing(\"GET\", true);\r\nws.register_resource(\"/{greeting}\", \u0026hwr);\r\n```\r\n3. Build and start example server `hello_with_get_arg` in a terminal.\r\n4. In a second terminal, run `curl http://localhost:8080/Howdy?name=Bob`\r\n\r\n**Expected behavior:** Server responds with text \"Howdy, Bob\"\r\n\r\n**Actual behavior:** Server responds with \"Howdy, \"\r\n\r\n**Reproduces how often:** 100%\r\n\r\n### Versions\r\n\r\n* OS version `Linux gd 6.8.0-50-generic #51~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 21 12:03:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux`\r\n* libhttpserver version 0.19.0, compiled\r\n* libmicrohttpd version 1.0.1, compiled\r\n\r\n### Additional Information\r\nFull example program, modified as specified in steps to reproduce.\r\n```\r\n#include \u003chttpserver.hpp\u003e\r\n\r\nclass hello_world_resource : public httpserver::http_resource {\r\n public:\r\n std::shared_ptr\u003chttpserver::http_response\u003e render(const httpserver::http_request\u0026 req) {\r\n return std::shared_ptr\u003chttpserver::http_response\u003e(new httpserver::string_response(std::string(req.get_arg(\"greeting\")) + \", \" + std::string(req.get_arg(\"name\"))));\r\n }\r\n};\r\n\r\nint main() {\r\n httpserver::webserver ws = httpserver::create_webserver(8080);\r\n\r\n hello_world_resource hwr;\r\n hwr.disallow_all();\r\n hwr.set_allowing(\"GET\", true);\r\n ws.register_resource(\"/{greeting}\", \u0026hwr);\r\n ws.start(true);\r\n\r\n return 0;\r\n}\r\n```\r\n","author":{"url":"https://github.com/dimitriadis-georgios","@type":"Person","name":"dimitriadis-georgios"},"datePublished":"2025-01-07T16:16:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/342/libhttpserver/issues/342"}
| 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:edd169fb-daeb-3902-aca9-8df1541432b9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A46A:3D21D:25445A7:3358905:6964DA6C |
| html-safe-nonce | e0147fa8992a369ff4356af41682b30934fb5bd1a90fc93e08d60e676005e54b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDZBOjNEMjFEOjI1NDQ1QTc6MzM1ODkwNTo2OTY0REE2QyIsInZpc2l0b3JfaWQiOiI3NDc2ODk1MjUzNTI4ODk0MDYwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0e7576acf09aed077306a93a89a910c0cf64504de3cda0f798c0aff9c57f0107 |
| hovercard-subject-tag | issue:2773233332 |
| 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/342/issue_layout |
| twitter:image | https://opengraph.githubassets.com/046caeff82e084d154b1b803347e0c563fe4d5760f0804d812f7af33cf5c4993/etr/libhttpserver/issues/342 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/046caeff82e084d154b1b803347e0c563fe4d5760f0804d812f7af33cf5c4993/etr/libhttpserver/issues/342 |
| 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 T... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dimitriadis-georgios |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5838582163a1256e5ebd5086b7e1dc5cea93d82086c9c8b1395fb50f6ddab28d |
| 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 | 8f997e7f84bd1db9537ba403fa68be0da3423594 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width