Skip to content

net/http: recommended way of handling MultipartForm and WithContext in middlewareΒ #71382

Closed as not planned
@Yiling-J

Description

@Yiling-J

I am currently working on fixing an issue in the OpenTelemetry Gin middleware: #6609. However, resolving this properly requires some agreement on the best approach. There are currently three options:

  1. Manually call RemoveAll on the copied context, as done in this PR, which mirrors what echo-contrib does.
  2. Parse the form before calling WithContext. This forces the form to be parsed, which might not be what the user intends.
  3. Reattach the MultipartForm to the original request, without automatic removal or parsing.

There are already some related issues, such as #58809, #67713, #69354, but the recommended approach is still unclear. OpenTelemetry supports many frameworks, and I think some of them have similar issues, not just Gin. Since this issue is closely tied to net/http, an official recommendation would be highly valuable and help us reach a consensus on the best way to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionIssues that are questions about using Go.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions