Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get HTTP headers in custom Marshaller? #4530

Closed
tymbaca opened this issue Jul 16, 2024 · 1 comment
Closed

How to get HTTP headers in custom Marshaller? #4530

tymbaca opened this issue Jul 16, 2024 · 1 comment

Comments

@tymbaca
Copy link

tymbaca commented Jul 16, 2024

📚 Documentation

I want to send data from client in multipart/form-data. And I want to parse it into proto-object with custom Marshaller.

mux := runtime.NewServeMux(
	runtime.WithMarshalerOption("multipart/form-data", mymarshaller.MyMarshaller{...}),
)

But to parse multipart/form-data I need to know the boundary, which is specified inside of Content-Type header: multipart/form-data; boundary=<BOUNDARY>

Inside of NewDecoder(r io.Reader) runtime.Decoder method I get io.Reader with only request body. At the same time, in debugger I see that io.Reader's underlying byte buffer contains the whole request (with headers), but the offset is set right before the body.

Is there any options to get r io.Reader with headers?

@johanbrandhorst
Copy link
Collaborator

You won't be able to pass headers into the marshaler, but you can combine a custom marshaler with a forwardResponseOption as described in #4483 (comment).

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

No branches or pull requests

2 participants