content-length: 0 stripped from empty local-reply bodies via prepareLocalReply, blocks mcp_json_rest_bridge's notifications/initialized ack
cc @guoyilin42 — this is about the TODO you left at line 968.
There's a TODO at mcp_json_rest_bridge_filter.cc:968:
// TODO(guoyilin42): We may need to explicitly set `content-length: 0` to prevent curl from
// hanging. `modify_headers` fails here as `sendLocalReply` removes it for empty bodies.
The ack for notifications/initialized sends an empty 202 with no modify_headers callback (it's nullptr), because the TODO already anticipated that passing one wouldn't help.
In Utility::prepareLocalReply (source/common/http/utility.cc), modify_headers_ runs first, but then for an empty, non-gRPC body the code unconditionally calls removeContentLength() and removeContentType() afterward. So even if the filter did set content-length: 0 through the callback, prepareLocalReply would strip it right after. Since that removal happens after the filter's callback runs, the fix has to live outside the filter.
Questions:
- Should the ack carry a small non-empty body, so
content-lengthgets set the normal way? - If it must stay empty, should
prepareLocalReplyemitcontent-length: 0for empty non-gRPC replies instead of removing it, or should the removal become conditional? - Is this actually a codec-level expectation? A 202 isn't a bodiless-by-spec status, so the HTTP/1 codec would normally add
content-length: 0on an empty end-stream response. If so, the curl hang might point elsewhere.
Happy to send a PR once there's agreement on where the fix is.
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
Closing as completed. #48165 merged and removed the TODO. The HTTP/1 codec already appends content-length: 0 to an empty end-stream response, so the ack is well-formed on HTTP/1 and HTTP/2. The test added in that PR now covers the HTTP/1 case.