-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[Question] Shall we follow the behavior of the document of http.ResponseWriter? #3191
Comments
🤖 Hey @kvii! Great to see you diving into the depths again. 🐙 Based on the context provided, it seems that the Kratos codebase does indeed follow the behavior of the Here are the relevant code snippets: var h = func(w http.ResponseWriter, r *http.Request) {
_ = json.NewEncoder(w).Encode(testData{Path: r.RequestURI})
} type handleFuncWrapper struct {
fn http.HandlerFunc
}
func (x *handleFuncWrapper) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
x.fn.ServeHTTP(writer, request)
} fn := func(w http.ResponseWriter, r *http.Request) {
data := &testData{Path: r.RequestURI}
_ = json.NewEncoder(w).Encode(data)
if r.Context().Value(testKey{}) != "test" {
w.WriteHeader(500)
}
} These examples show that the Kratos codebase uses the As for the specific behavior of // ServeHTTP should write reply headers and data to the ResponseWriter and then return.
func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) {
s.Handler.ServeHTTP(res, req)
} In this method, the However, the specific behavior of
Reference: Go standard library documentation I hope this answers your question. If you need further clarification, please let me know. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
I think it's necessary to follow the behavior of the document of http.ResponseWriter. It's hard to explain "why". But you can see this repo.
The text was updated successfully, but these errors were encountered: