(w http.ResponseWriter, r *http.Request)
| 95 | } |
| 96 | |
| 97 | func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 98 | var sid string |
| 99 | if r.URL.Path == OpenServiceMCPPath { |
| 100 | sid = r.Header.Get("X-Service-Id") |
| 101 | if sid == "" { |
| 102 | http.NotFound(w, r) |
| 103 | return |
| 104 | } |
| 105 | } else { |
| 106 | id, err := genPath(r.URL.Path) |
| 107 | if err != nil { |
| 108 | w.WriteHeader(http.StatusBadRequest) |
| 109 | w.Write([]byte(err.Error())) |
| 110 | return |
| 111 | } |
| 112 | sid = id |
| 113 | } |
| 114 | |
| 115 | ser, has := s.Get(sid) |
| 116 | if has { |
| 117 | ser.ServeHTTP(w, r) |
| 118 | return |
| 119 | } |
| 120 | http.NotFound(w, r) |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | func genPath(path string) (sid string, err error) { |
| 125 | path = strings.TrimSuffix(path, "/") |
no test coverage detected