上一节我们试着写了一个RPC的请求实例,通过分析源码知道了RPC服务的创建流程,以及Http RPC server创建过程,Http RPC Client的请求流程。
这一节,先分析一下Http RPC server如何处理client的请求。然后再分析一下IPC RPC的处理流程。
一,Http RPC server处理Client的请求。
回到上一节startHTTP() 里面HTTPServer初始化的方法
func NewHTTPServer(cors []string, vhosts []string, srv *Server) *http.Server {
// Wrap the CORS-handler within a host-handler
handler := newCorsHandler(srv, cors)
handler = newVHostHandler(vhosts, handler)
return &http.Server{Handler: handler}
}
// ServeHTTP serves JSON-RPC requests over HTTP.
func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Permit dumb empty requests for remote health-checks (AWS)
if r.Method == http.MethodGet && r.Cont