MCPcopy
hub / github.com/puma/puma-dev / ServeHTTP

Method ServeHTTP

dev/http.go:132–193  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

130}
131
132func (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 {

Callers

nothing calls this directly

Calls 6

removeTLDMethod · 0.95
FindAppByDomainNameMethod · 0.80
AddMethod · 0.80
WaitTilReadyMethod · 0.80
AddressMethod · 0.80

Tested by

no test coverage detected