Title: Fixed multipart boundary "+++" (since 0.29.0) truncates uploads whose content contains \r\n--+++ · Issue #1509 · openapi-generators/openapi-python-client · GitHub
Open Graph Title: Fixed multipart boundary "+++" (since 0.29.0) truncates uploads whose content contains \r\n--+++ · Issue #1509 · openapi-generators/openapi-python-client
X Title: Fixed multipart boundary "+++" (since 0.29.0) truncates uploads whose content contains \r\n--+++ · Issue #1509 · openapi-generators/openapi-python-client
Description: Describe the bug Since 0.29.0 (#1005), every multipart/form-data request body is sent with a fixed boundary: headers["Content-Type"] = "multipart/form-data; boundary=+++" httpx reads the boundary back from that header when it encodes fil...
Open Graph Description: Describe the bug Since 0.29.0 (#1005), every multipart/form-data request body is sent with a fixed boundary: headers["Content-Type"] = "multipart/form-data; boundary=+++" httpx reads the boundary b...
X Description: Describe the bug Since 0.29.0 (#1005), every multipart/form-data request body is sent with a fixed boundary: headers["Content-Type"] = "multipart/form-data; boundary=+++" httpx ...
Opengraph URL: https://github.com/openapi-generators/openapi-python-client/issues/1509
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fixed multipart boundary \"+++\" (since 0.29.0) truncates uploads whose content contains \\r\\n--+++","articleBody":"**Describe the bug**\n\nSince 0.29.0 (#1005), every `multipart/form-data` request body is sent with a fixed boundary:\n\n```python\nheaders[\"Content-Type\"] = \"multipart/form-data; boundary=+++\"\n```\n\nhttpx reads the boundary back from that header when it encodes `files=`, so the header and the body agree. But a boundary must not occur in the content it delimits (RFC 2046 §5.1.1), and a fixed three-character one can. An uploaded file that contains the bytes `\\r\\n--+++` is split at that point: the server receives a truncated file, and the rest of it as a malformed extra part.\n\nThis used to work for endpoints with a single `multipart/form-data` body. Up to 0.28.x their `_get_kwargs` set no `Content-Type`, and httpx generated a random boundary for each request. #1005 fixed the endpoints with several body types, which sent no boundary at all (#947). As a side effect, the single-body endpoints changed from a random boundary to the fixed one.\n\n**OpenAPI Spec File**\n\n```yaml\nopenapi: 3.0.3\ninfo: {title: Boundary repro, version: \"1.0\"}\npaths:\n /upload:\n post:\n operationId: upload\n requestBody:\n required: true\n content:\n multipart/form-data:\n schema:\n type: object\n properties:\n file: {type: string, format: binary}\n responses:\n \"200\": {description: OK}\n```\n\nGenerated with `openapi-python-client generate --path openapi.yaml --meta none --output-path client`, then:\n\n```python\nimport email.parser, email.policy, io\nimport httpx\nfrom client import Client\nfrom client.api.default import upload\nfrom client.models.upload_body import UploadBody\nfrom client.types import File\n\ncontent = b\"first line\\r\\n--+++\\r\\nstill the same file\\r\\n\"\nsent = []\ntransport = httpx.MockTransport(lambda r: (r.read(), sent.append(r), httpx.Response(200))[2])\nclient = Client(base_url=\"http://test\", httpx_args={\"transport\": transport})\nupload.sync_detailed(client=client, body=UploadBody(file=File(payload=io.BytesIO(content), file_name=\"a.txt\")))\n\nrequest = sent[-1]\nmessage = email.parser.BytesParser(policy=email.policy.HTTP).parsebytes(\n b\"Content-Type: \" + request.headers[\"content-type\"].encode() + b\"\\r\\n\\r\\n\" + request.content\n)\nparts = list(message.iter_parts())\nprint(len(parts), parts[0].get_payload(decode=True))\n# 2 b'first line'\n```\n\nThe file arrives as `b'first line'`, and the rest of it becomes a second part. A server sees the same: Rack 3.2.6, which Rails uses, parses this request into `file` = `\"first line\"` plus a stray parameter named `text/plain`.\n\n**Desktop (please complete the following information):**\n - OS: Linux (Ubuntu)\n - Python Version: 3.12.13\n - openapi-python-client version: 0.29.1 (httpx 0.28.1)\n\n**Additional context**\n\nTwo ways to keep #1005's fix without the fixed boundary:\n\n1. **A random boundary for each request, in the template.** For example, `boundary = secrets.token_hex(16)` in `_get_kwargs`, used in the header. httpx would then encode the body with it, as it does with `+++` today. httpx's own default is 16 random bytes in hex.\n2. **No `Content-Type` for an endpoint whose only body is `multipart/form-data`,** as before 0.29.0, so that httpx sets the header with its own random boundary. Only the endpoints with several body types would need the explicit header from (1).\n\nIn practice a collision needs those exact seven bytes in the uploaded content, so it is rare with binary files. But it silently truncates the file, and it reaches the server as a successful upload.\n","author":{"url":"https://github.com/alanwilter","@type":"Person","name":"alanwilter"},"datePublished":"2026-11-05T12:48:29Z","url":"https://github.com/openapi-generators/openapi-python-client/issues/1509"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:9b3d018e-dac9-aa9d-1e28-a9151dd608a4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCDC:129351:765FE3:974118:6B035A99 |
| html-safe-nonce | 1e3f9d090f4b01e2169cbbdc59b4c55554477c477c3bd9f3b36b0caf60af7ed9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0RDOjEyOTM1MTo3NjVGRTM6OTc0MTE4OjZCMDM1QTk5IiwidmlzaXRvcl9pZCI6IjQ0Nzg0ODI2MTc0NjkxOTY5NTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a349c013fb8f9f3b87ace606f2c35363b6bdb88ddff064c7c3666f31f1f86f6e |
| hovercard-subject-tag | issue:6223489591 |
| 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/openapi-generators/openapi-python-client/1509/issue_layout |
| twitter:image | https://opengraph.githubassets.com/74ba0b376b32017fe24d6ed71af90b8d5c80d2732c18fdc8efff0f770a0c5c4a/openapi-generators/openapi-python-client/issues/1509 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/74ba0b376b32017fe24d6ed71af90b8d5c80d2732c18fdc8efff0f770a0c5c4a/openapi-generators/openapi-python-client/issues/1509 |
| og:image:alt | Describe the bug Since 0.29.0 (#1005), every multipart/form-data request body is sent with a fixed boundary: headers["Content-Type"] = "multipart/form-data; boundary=+++" httpx reads the boundary b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alanwilter |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/openapi-generators/openapi-python-client git https://github.com/openapi-generators/openapi-python-client.git |
| octolytics-dimension-user_id | 84925606 |
| octolytics-dimension-user_login | openapi-generators |
| octolytics-dimension-repository_id | 240776275 |
| octolytics-dimension-repository_nwo | openapi-generators/openapi-python-client |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 240776275 |
| octolytics-dimension-repository_network_root_nwo | openapi-generators/openapi-python-client |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width