(w http.ResponseWriter, req *http.Request)
| 130 | } |
| 131 | |
| 132 | func (h *HTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
| 133 | if h.Debug { |
| 134 | fmt.Fprintf(os.Stderr, "%s: %s '%s' (host=%s)\n", |
| 135 | time.Now().Format(time.RFC3339Nano), |
| 136 | req.Method, req.URL.Path, req.Host) |
| 137 | } |
| 138 | |
| 139 | if req.Host == "puma-dev" { |
| 140 | h.mux.ServeHTTP(w, req) |
| 141 | return |
| 142 | } |
| 143 | |
| 144 | name := h.removeTLD(req.Host) |
| 145 | |
| 146 | app, err := h.Pool.FindAppByDomainName(name) |
| 147 | if err != nil { |
| 148 | if err == ErrUnknownApp { |
| 149 | h.Events.Add("unknown_app", "name", name, "host", req.Host) |
| 150 | } else { |
| 151 | h.Events.Add("lookup_error", "error", err.Error()) |
| 152 | } |
| 153 | |
| 154 | w.WriteHeader(500) |
| 155 | w.Write([]byte(err.Error())) |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | err = app.WaitTilReady() |
| 160 | if err != nil { |
| 161 | w.WriteHeader(500) |
| 162 | w.Write([]byte(err.Error())) |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | if h.shouldServePublicPathForApp(app, req) { |
| 167 | safeURLPath := path.Clean(req.URL.Path) |
| 168 | path := filepath.Join(app.dir, "public", safeURLPath) |
| 169 | |
| 170 | fi, err := os.Stat(path) |
| 171 | if err == nil && !fi.IsDir() { |
| 172 | if ofile, err := os.Open(path); err == nil { |
| 173 | http.ServeContent(w, req, req.URL.Path, fi.ModTime(), io.ReadSeeker(ofile)) |
| 174 | return |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if req.TLS == nil { |
| 180 | req.Header.Set("X-Forwarded-Proto", "http") |
| 181 | } else { |
| 182 | req.Header.Set("X-Forwarded-Proto", "https") |
| 183 | } |
| 184 | |
| 185 | req.URL.Scheme, req.URL.Host = app.Scheme, app.Address() |
| 186 | if app.Scheme == "httpu" { |
| 187 | req.URL.Scheme, req.URL.Host = "http", app.Address() |
| 188 | h.unixProxy.ServeHTTP(w, req) |
| 189 | } else { |
nothing calls this directly
no test coverage detected