Comments (5)
Thanks for your issue! I'd like to ask some clarifying questions:
- Could you elaborate on the behavior of the
net/http
handler in this case? If they choose to only do this for "small responses", why should we do anything differently? - Is this something that could be by a custom middleware instead? I'm thinking something that wraps the
http.ResponseWriter
and counts the bytes written, setting the header before writing it to the wire. That would mean we wouldn't have to add it as an option here. - Thanks for the PR, but please refrain from submitting anything until we've discussed the best way forward.
from grpc-gateway.
Hey @johanbrandhorst,
On question 1:
// If [ResponseWriter.WriteHeader] has not yet been called, Write calls
// WriteHeader(http.StatusOK) before writing the data. If the Header
// does not contain a Content-Type line, Write adds a Content-Type set
// to the result of passing the initial 512 bytes of written data to
// [DetectContentType]. Additionally, if the total size of all written
// data is under a few KB and there are no Flush calls, the
// Content-Length header is added automatically.
https://github.com/golang/go/blob/960fa9bf66139e535d89934f56ae20a0e679e203/src/net/http/server.go#L1582 also has some additional comments.
The library doesn't know if the calling code is going to call write once or multiple times. In this case, we know the Write method is only called once as long as doForwardTrailers isn't set.
On question 2:
I'm not sure of a way this can be done without writing the data to a buffer first, which adds additional allocations. This could be problematic for very large responses.
from grpc-gateway.
Thanks for your responses. I wonder if we can't just enable this behavior by default since we know the size of the buffer we want to write. Worst case it's going to add a content-length header where we didn't before, but that seems like a better experience. What do you think? Feel free to update the PR and remove the option if you agree.
from grpc-gateway.
I'm supportive of that, the only edge case I could think of is if a user already had some other middleware that was writing the header and maybe causing some trouble there. I'll update the PR now.
from grpc-gateway.
I recreated the PR with a cleaner history
from grpc-gateway.
Related Issues (20)
- WriteHeader is not called on 200s HOT 1
- How to set cookie to http response header? Why it doesn't work. HOT 2
- Adding custom mux endpoint to openapi output HOT 3
- The API Gateway Vision HOT 2
- Support disabling default response rendering in bazel rule HOT 1
- Example and pattern annotations are not respect for query and path parameters HOT 8
- FieldMask as query param is not converted to snake case HOT 1
- an google.protobuf.Any type how to get openapiv2 output? HOT 1
- omit-enum-default-value Generates Invalid Spec for Enums with a Single Value HOT 1
- Log level for errors is "info" HOT 5
- On `context deadline exceeded`, response headers aren't set HOT 3
- Add support for Etag & If-None-Match headers HOT 6
- TestOutgoingTrailerMatcher is non-deterministic
- How to remove @type or type_url after marshal google.protobuf.Any? HOT 3
- Feat: add http handler middleware HOT 1
- `X-Forwarded-For` header is not handled correctly HOT 2
- README.md: link to Wiki of "tool dependency" has been moved to go.dev HOT 1
- undefined: grpc.NewClient HOT 1
- proposal: Use version info from runtime/debug:BuildInfo when installed by go install HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-gateway.