@@ -214,7 +214,7 @@ func (reg *Server) serve(w http.ResponseWriter, req *http.Request) {
214
214
215
215
// The blobFor operation's context must be independent of this request. Even if we do not
216
216
// serve this request in time, we might want to serve another from the same ref in the future.
217
- blob , hash , err := reg .refstore .BlobFor (context .Background (), ref , false )
217
+ blobFS , hash , err := reg .refstore .BlobFor (context .Background (), ref , false )
218
218
if err == errdefs .ErrNotFound {
219
219
http .Error (w , fmt .Sprintf ("image %s not found: %q" , html .EscapeString (ref ), err ), http .StatusNotFound )
220
220
return
@@ -245,39 +245,43 @@ func (reg *Server) serve(w http.ResponseWriter, req *http.Request) {
245
245
w .Header ().Set ("Cache-Control" , "no-cache" )
246
246
}
247
247
248
+ var fs http.FileSystem = blobFS
249
+ if workdir != "" {
250
+ fs = prefixingFilesystem {Prefix : workdir , FS : blobFS }
251
+ }
252
+
248
253
// http.FileServer has a special case where ServeFile redirects any request where r.URL.Path
249
254
// ends in "/index.html" to the same path, without the final "index.html".
250
255
// We do not want this behaviour to make the gitpod-ide-index mechanism in ws-proxy work.
251
- imagePath := strings .TrimPrefix (req .URL .Path , pathPrefix )
252
- if imagePath == "/index.html" || imagePath == "/" {
253
- fn := filepath .Join (workdir , "index.html" )
254
-
255
- fc , err := blob .Open (fn )
256
+ resourcePath := strings .TrimPrefix (req .URL .Path , pathPrefix )
257
+ if resourcePath == "/" {
258
+ resourcePath = "/index.html"
259
+ }
260
+ if strings .HasSuffix (resourcePath , "/index.html" ) {
261
+ fc , err := fs .Open (resourcePath )
256
262
if err != nil {
257
- log .WithError (err ).WithField ("fn" , fn ).Error ("cannot stat index.html " )
263
+ log .WithError (err ).WithField ("fn" , resourcePath ).Error ("cannot open resource " )
258
264
http .Error (w , http .StatusText (http .StatusNotFound ), http .StatusNotFound )
259
265
return
260
266
}
261
267
defer fc .Close ()
262
268
263
- var modTime time.Time
264
- if s , err := fc .Stat (); err == nil {
265
- modTime = s .ModTime ()
269
+ stat , err := fc .Stat ()
270
+ if err != nil {
271
+ log .WithError (err ).WithField ("fn" , resourcePath ).Error ("cannot stat resource" )
272
+ http .Error (w , http .StatusText (http .StatusNotFound ), http .StatusNotFound )
273
+ return
266
274
}
267
275
268
276
content , err := inlineVars (req , fc , inlineReplacements )
269
277
if err != nil {
270
278
log .WithError (err ).Error ()
271
279
}
272
- http .ServeContent (w , req , "index.html" , modTime , content )
280
+
281
+ http .ServeContent (w , req , stat .Name (), stat .ModTime (), content )
273
282
return
274
283
}
275
284
276
- var fs http.FileSystem
277
- fs = blob
278
- if workdir != "" {
279
- fs = prefixingFilesystem {Prefix : workdir , FS : fs }
280
- }
281
285
http .StripPrefix (pathPrefix , http .FileServer (fs )).ServeHTTP (w , req )
282
286
}
283
287
0 commit comments