Skip to content

Fix mesh-forwarded image requests losing body data#367

Open
v-mwalk wants to merge 1 commit into
codeproject:mainfrom
v-mwalk:Fix-mesh-forwarded-image-requests-losing-body-data
Open

Fix mesh-forwarded image requests losing body data#367
v-mwalk wants to merge 1 commit into
codeproject:mainfrom
v-mwalk:Fix-mesh-forwarded-image-requests-losing-body-data

Conversation

@v-mwalk

@v-mwalk v-mwalk commented Jul 11, 2026

Copy link
Copy Markdown

Three stacked bugs caused every image sent to a mesh-forwarded route (e.g. POST /v1/vision/detection) to arrive at the receiving server with no image data, whether from a real client or the mesh's own periodic route-probing:

ForwardAsync() copied Content-Type/Content-Length onto HttpRequestMessage.Headers instead of Content.Headers, so HttpClient never sent a usable Content-Type (with multipart boundary) on the wire. The receiving Kestrel pipeline couldn't parse the body as multipart form data and Request.Form.Files came back empty.

Forwarding exceptions were logged via Debug.WriteLine, a no-op in Release builds and never routed through CodeProject.AI's own log system, so failures were invisible. Wired DispatchRemoteRequest's catch block up to ILogger instead, and surfaced ex.Message directly in the error response.

With both above fixed, forwarding started throwing "Sent 0 request content bytes, but Content-Length promised NNNNN" - the request body stream was already consumed upstream by the time ForwardAsync() read it. Fixed by enabling request buffering as the first middleware in Startup.Configure() and rewinding the body position immediately before building the forwarded request.

Also fixes dashboard's "Accepting Requests" line (both server-side in MeshSummary.cs and client-side in dashboard.js) read AllowRequestForwarding instead of AcceptForwardedRequests, so a receive-only mesh server showed as not accepting forwarded requests even while correctly processing them.

FYI @ChrisMaunder :-)

Three stacked bugs caused every image sent to a mesh-forwarded route (e.g. POST /v1/vision/detection) to arrive at the receiving server with no image data, whether from a real client or the mesh's own periodic route-probing:

ForwardAsync() copied Content-Type/Content-Length onto HttpRequestMessage.Headers instead of Content.Headers, so HttpClient never sent a usable Content-Type (with multipart boundary) on the wire. The receiving Kestrel pipeline couldn't parse the body as multipart form data and Request.Form.Files came back empty.

Forwarding exceptions were logged via Debug.WriteLine, a no-op in Release builds and never routed through CodeProject.AI's own log system, so failures were invisible. Wired DispatchRemoteRequest's catch block up to ILogger<ProxyController> instead, and surfaced ex.Message directly in the error response.

With both above fixed, forwarding started throwing "Sent 0 request content bytes, but Content-Length promised NNNNN" - the request body stream was already consumed upstream by the time ForwardAsync() read it. Fixed by enabling request buffering as the first middleware in Startup.Configure() and rewinding the body position immediately before building the forwarded request.

Also fixes dashboard's "Accepting Requests" line (both server-side in MeshSummary.cs and client-side in dashboard.js) read AllowRequestForwarding instead of AcceptForwardedRequests, so a receive-only mesh server showed as not accepting forwarded requests even while correctly processing them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant