-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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 print out all request routes, including intercepted or intercepted requests without content type #3105
Comments
🤖 Hello @zkcrescent, Welcome to the Kratos repository! I'm Dosu, a bot here to assist you. While we wait for a human maintainer to respond, feel free to ask me anything regarding solving bugs, answering questions, or even becoming a contributor. I'm here to assist you in the meantime. 在Kratos框架中,您可以使用中间件来打印所有请求路由,包括被拦截的或者没有content type被拦截的请求。中间件是一系列处理器的链,可以在请求到达最终处理器之前处理这些请求。在您的情况下,您可以创建一个中间件来记录所有传入的请求。 在提供的上下文中,已经定义了三个中间件函数: 以下是如何修改 func loggingFilter(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Log the method, URI, and content type of the request
log.Println("logging:", r.Method, r.RequestURI, r.Header.Get("Content-Type"))
// Call the next handler, which can be another middleware in the chain, or the final handler.
next.ServeHTTP(w, r)
})
} 在 srv := NewServer(
Filter(corsFilter, loggingFilter),
) 这意味着 Kratos框架通过使用Router结构来处理由protobuf生成的HTTP路由。Router结构有一个名为Handle的方法,该方法使用URL路径和方法的匹配器注册新路由。 Handle方法接受HTTP方法,相对路径,HandlerFunc和可选的过滤器。HandlerFunc是一个服务HTTP请求的函数。过滤器是可以修改HTTP请求或响应的函数。 Router结构还有每个HTTP方法(GET,POST,PUT,PATCH,DELETE,CONNECT,OPTIONS,TRACE)的便利方法,这些方法使用适当的HTTP方法调用Handle方法。 Kratos框架通过使用中间件来处理被拦截的请求。Kratos中的中间件是一系列处理器的链,每个处理器决定是否将请求传递给链中的下一个处理器。 在提供的上下文中,使用 然后调用 希望这些信息对您有所帮助。如果您有任何其他问题或需要进一步的澄清,请随时告诉我。 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. |
Based on what you have mentioned so far, I am not sure what exactly you want to ask |
Hi, @zkcrescent, I'm helping the Kratos team manage their backlog and am marking this issue as stale. The issue was opened by you and is related to difficulty in printing out all request routes, including intercepted requests without content type, using protobuf-generated HTTP routes, middleware, and filters. There has been some activity on the issue, including a response from dosubot providing a detailed explanation and example code related to the issue. Additionally, shenqidebaozi has expressed uncertainty about the specific question being asked. Could you please confirm if this issue is still relevant to the latest version of the Kratos repository? If it is, please let the Kratos team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days. Thank you for your understanding and cooperation. |
protobuf 生成的HTTP路由,middleware 和filter 都不行
The text was updated successfully, but these errors were encountered: