Title: [BUG] Unable to access Content-Type of file when part of multipart form · Issue #229 · etr/libhttpserver · GitHub
Open Graph Title: [BUG] Unable to access Content-Type of file when part of multipart form · Issue #229 · etr/libhttpserver
X Title: [BUG] Unable to access Content-Type of file when part of multipart form · Issue #229 · etr/libhttpserver
Description: Prerequisites [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=&q=repo:etr/libhttpserver&type=Issues Description When uploading a file as part of a m...
Open Graph Description: Prerequisites [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=&q=repo:etr/libhttpserver&type=Issues Descript...
X Description: Prerequisites [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=&q=repo:etr/libhttpserver&type=Iss...
Opengraph URL: https://github.com/etr/libhttpserver/issues/229
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG] Unable to access Content-Type of file when part of multipart form","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\nWhen uploading a file as part of a multipart form, the Content-Type, and filename are not accessible from the http_request object. I have tried get_args(), get_headers(), and get_footers(). However if i dump the body with get_content(), I can see the fields in the body, but they are not hoisted into higher level objects. \r\n\r\n### Example Code\r\n```c++\r\n#include \u003ciostream\u003e\r\n#include \u003calgorithm\u003e\r\n\r\n#include \u003chttpserver.hpp\u003e\r\n\r\nusing namespace httpserver;\r\n\r\nclass file_resource : public http_resource {\r\n public :\r\n const std::shared_ptr\u003chttp_response\u003e render_POST(const http_request\u0026 req) {\r\n\r\n //Loop through the headers map and output them\r\n const auto\u0026 headers = req.get_headers();\r\n std::for_each(headers.begin(), headers.end(), [](auto\u0026 p){\r\n std::cout \u003c\u003c p.first \u003c\u003c \" -\u003e \" \u003c\u003c p.second \u003c\u003c std::endl;\r\n });\r\n\r\n //Loop through the args map and output them\r\n const auto\u0026 args = req.get_args(); \r\n std::for_each(args.begin(), args.end(), [](auto\u0026 p) {\r\n std::cout \u003c\u003c p.first \u003c\u003c \" -\u003e \" \u003c\u003c p.second \u003c\u003c std::endl;\r\n });\r\n\r\n std::cout \u003c\u003c \"Body: \" \u003c\u003c req.get_content() \u003c\u003c std::endl;\r\n return std::shared_ptr\u003chttp_response\u003e(new string_response(\"OK\"));\r\n }\r\n};\r\n\r\nvoid custom_access_log(const std::string\u0026 url) {\r\n std::cout \u003c\u003c \"Request to: \" \u003c\u003c url \u003c\u003c std::endl;\r\n}\r\n\r\nvoid custom_error_log(const std::string\u0026 error) {\r\n std::cout \u003c\u003c \"Error: \" \u003c\u003c error \u003c\u003c std::endl;\r\n}\r\n\r\nint main() {\r\n webserver ws = create_webserver(8080)\r\n .log_access(custom_access_log)\r\n .log_error(custom_error_log);\r\n\r\n file_resource fr;\r\n\r\n ws.register_resource(\"/file\", \u0026fr);\r\n\r\n ws.start(true);\r\n\r\n return 0;\r\n}\r\n```\r\n\r\n### Steps to Reproduce\r\n\r\n1. Compile example code above\r\n2. `curl -X POST -F upload=@\u003csome_file\u003e.jpg localhost:8080/file`\r\n3. the \"upload\" argument will have the file data, but the Content-Type, and original filename are not accessible \r\n4. Looking at the output, you can see the get_contents() string contains the Content-Type and filename\r\n```\r\nMethod: POST, Body: --------------------------ea9b4d3e74b2950b\r\nContent-Disposition: form-data; name=\"upload\"; filename=\"suite_and_tie.jpg\"\r\nContent-Type: image/jpeg\r\n```\r\n\r\n**Expected behavior:** \r\nSome way to access the filename and Content-Type of the file \r\n\r\n**Actual behavior:** \r\nNo way to access it easily\r\n\r\n**Reproduces how often:** 100%\r\n","author":{"url":"https://github.com/jmslocum","@type":"Person","name":"jmslocum"},"datePublished":"2021-04-10T01:34:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/229/libhttpserver/issues/229"}
| 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:a1b776bc-45bd-8b5d-6803-59368c79242b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AAB0:3DC17:1B328BD:2529EDC:6A53FDC4 |
| html-safe-nonce | 4b7f1d4766ad2fbdb00bc263a8c409a165bed8086c56d36d42a225828e9abf62 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUIwOjNEQzE3OjFCMzI4QkQ6MjUyOUVEQzo2QTUzRkRDNCIsInZpc2l0b3JfaWQiOiI3OTcyNzE0MDkzOTEwNDE5ODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7df6064c5f13008a9f2b7bd31dd2e466452b186d586c2b1aa364b5620a07f70d |
| hovercard-subject-tag | issue:854953537 |
| 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/229/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0c073a47867000721247dc1498e8fc5b7c4af363683a4460907df8e2727b5781/etr/libhttpserver/issues/229 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0c073a47867000721247dc1498e8fc5b7c4af363683a4460907df8e2727b5781/etr/libhttpserver/issues/229 |
| og:image:alt | Prerequisites [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=&q=repo:etr/libhttpserver&type=Issues Descript... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jmslocum |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width