func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	if req.Method != http.MethodGet && req.Method != http.MethodHead {
		rw.Header().Set("Allow", http.MethodGet+", "+http.MethodHead)
		http.Error(rw, "Method Not Allowed\n\nmethod should be GET or HEAD", http.StatusMethodNotAllowed)

		return
	}

	if strings.HasSuffix(req.URL.Path, "/index.html") {
		localRedirect(rw, req, "./")

		return
	}

	fn := strings.TrimPrefix(req.URL.Path, "/")
	ae := req.Header.Get("Accept-Encoding")

	if s.info[fn].isDir {
		localRedirect(rw, req, path.Base(req.URL.Path)+"/")

		return
	}

	if fn == "" || strings.HasSuffix(fn, "/") {
		fn += "index.html"
	}

	// Always add Accept-Encoding to Vary to prevent intermediate caches corruption.
	rw.Header().Add("Vary", "Accept-Encoding")

	if ae != "" {
		minInfo, minEnc := s.minEnc(strings.ToLower(ae), fn)

		if minInfo.hash != "" {
			// Copy compressed data into response.
			s.serve(rw, req, fn, minEnc.FileExt, minEnc.ContentEncoding, minInfo, nil)

			return
		}
	}

	// Copy uncompressed data into response.
	uncompressedInfo, uncompressedFound := s.info[fn]
	if uncompressedFound {
		s.serve(rw, req, fn, "", "", uncompressedInfo, nil)

		return
	}

	// Decompress compressed data into response.
	for _, enc := range s.Encodings {
		info, found := s.info[fn+enc.FileExt]
		if !found || enc.Decoder == nil || info.isDir {
			continue
		}

		info.hash += "U"
		info.size = 0
		s.serve(rw, req, fn, enc.FileExt, "", info, enc.Decoder)

		return
	}

	http.NotFound(rw, req)
}
// ServeHTTP serves static files.
//
// For compatibility with std http.FileServer:
// if request path ends with /index.html, it is redirected to base directory;
// if request path points to a directory without trailing "/", it is redirected to a path with trailing "/".
ServeHTTP serves static files.

For compatibility with std http.FileServer:
if request path ends with /index.html, it is redirected to base directory;
if request path points to a directory without trailing "/", it is redirected to a path with trailing "/".
// ServeHTTP serves static files . // // For compatibility with std http . FileServer : // if request path ends with / index . html it is redirected to base directory ; // if request path points to a directory without trailing " / " it is redirected to a path with trailing " / " .
func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	if req.Method != http.MethodGet && req.Method != http.MethodHead {
		rw.Header().Set("Allow", http.MethodGet+", "+http.MethodHead)
		http.Error(rw, "Method Not Allowed\n\nmethod should be GET or HEAD", http.StatusMethodNotAllowed)
		return
	}
	if strings.HasSuffix(req.URL.Path, "/index.html") {
		localRedirect(rw, req, "./")
		return
	}
	fn := strings.TrimPrefix(req.URL.Path, "/")
	ae := req.Header.Get("Accept-Encoding")
	if s.info[fn].isDir {
		localRedirect(rw, req, path.Base(req.URL.Path)+"/")
		return
	}
	if fn == "" || strings.HasSuffix(fn, "/") {
		fn += "index.html"
	}
	rw.Header().Add("Vary", "Accept-Encoding")
	if ae != "" {
		minInfo, minEnc := s.minEnc(strings.ToLower(ae), fn)
		if minInfo.hash != "" {
			s.serve(rw, req, fn, minEnc.FileExt, minEnc.ContentEncoding, minInfo, nil)
			return
		}
	}
	uncompressedInfo, uncompressedFound := s.info[fn]
	if uncompressedFound {
		s.serve(rw, req, fn, "", "", uncompressedInfo, nil)
		return
	}
	for _, enc := range s.Encodings {
		info, found := s.info[fn+enc.FileExt]
		if !found || enc.Decoder == nil || info.isDir {
			continue
		}
		info.hash += "U"
		info.size = 0
		s.serve(rw, req, fn, enc.FileExt, "", info, enc.Decoder)
		return
	}
	http.NotFound(rw, req)
}
func ( s * Server ) ServeHTTP ( rw http . ResponseWriter , req * http . Request ) { if req . Method != http . MethodGet && req . Method != http . MethodHead { rw . Header ( ) . Set ( " " , http . MethodGet + " " + http . MethodHead ) http . Error ( rw , " \n \n " , http . StatusMethodNotAllowed ) return } if strings . HasSuffix ( req . URL . Path , " " ) { localRedirect ( rw , req , " " ) return } fn := strings . TrimPrefix ( req . URL . Path , " " ) ae := req . Header . Get ( " " ) if s . info [ fn ] . isDir { localRedirect ( rw , req , path . Base ( req . URL . Path ) + " " ) return } if fn == " " || strings . HasSuffix ( fn , " " ) { fn += " " } rw . Header ( ) . Add ( " " , " " ) if ae != " " { minInfo , minEnc := s . minEnc ( strings . ToLower ( ae ) , fn ) if minInfo . hash != " " { s . serve ( rw , req , fn , minEnc . FileExt , minEnc . ContentEncoding , minInfo , nil ) return } } uncompressedInfo , uncompressedFound := s . info [ fn ] if uncompressedFound { s . serve ( rw , req , fn , " " , " " , uncompressedInfo , nil ) return } for _ , enc := range s . Encodings { info , found := s . info [ fn + enc . FileExt ] if ! found || enc . Decoder == nil || info . isDir { continue } info . hash += " " info . size = 0 s . serve ( rw , req , fn , enc . FileExt , " " , info , enc . Decoder ) return } http . NotFound ( rw , req ) }
ServeHTTP serves static files.
ServeHTTP serves static files .
// Always add Accept-Encoding to Vary to prevent intermediate caches corruption. // Copy compressed data into response. // Copy uncompressed data into response. // Decompress compressed data into response.