-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
export some functions to let serveMux.protoErrorHandler interface work well #405 #419
Conversation
I signed it! |
I signed it! |
ready to merge :) |
What is the reason for this proposed change? Generally we should keep the exposed api as small as possible and it's not clear why this would be desirable. As is I would reject this change proposal. |
If you think
is not commonly used. But I think sometime, we need this 3 funcs. |
The standard DefaultHTTPError use these 3 funcs. see errors.go :81 |
If these 3 func is commonly used( every request). We should write a interface to let customize func run this 3 func automatically. |
I am against these proposed commits themselves. But I understand the problem behind the proposal. So I'd like to propose a variant of the solution. First of all, I basically agree with @tmc. I don't want to expose the functions as they are because they are very implementation details of the runtime and they are not designed from the perspective of the right granularity of APIs. On the other hand, it have to say that it has been getting hard for users to write a right implementation of custom w.Header().Set("Content-Type", "application/json")
...
st := HTTPStatusFromCode(grpc.Code(err))
w.WriteHeader(st)
w.Write(buf) in an earlier version. So it was easier to reproduce. So I propose
The function would be, roughly type ErrorResponse struct {
Code int
ContentType string
MD ServerMetadata
Body []byte
}
func WriteErrorResponse(ctx context.Context, w http.ResponseWriter, mux *ServeMux, resp ErrorResponse) error {
w.Header().Del("Trailer")
w.Header().Set("Content-Type", resp.ContentType)
handleForwardResponseServerMetadata(w, mux, resp.MD)
handleForwardResponseTrailerHeader(w, resp.MD)
w.WriteHeader(resp.Code)
if _, err := w.Write(resp.Body); err != nil {
return err
}
handleForwardResponseTrailer(w, md)
return nil
} |
@yugui What you said is just my want to say, lovely lady. But I do not understand your codes |
IIUC, if we had something like Is this understanding correct? |
Yes. Finally I understand your codes :) |
@yugui, @jinleileiking, any update on this issue? i'm willing to carry on any pending changes to make sure this is merged as soon as possible. |
I think we should wait @yugui codes :) |
I close this issue. |
#405