github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2013/oscon-dl/after.go (about) 1 // +build ignore,OMIT 2 3 package download 4 5 func (s *Server) handleDownload(w http.ResponseWriter, r *http.Request) { 6 s.addActiveDownloadTotal(1) 7 defer s.addActiveDownloadTotal(-1) 8 if !isGetOrHead(w, r) { 9 return 10 } 11 uctx, err := s.newUserContext(r) 12 // ... 13 pl, cacheable, err := s.chooseValidPayloadToDownload(uctx) 14 // ... 15 content, err := pl.content() 16 // ... 17 defer content.Close() 18 w.Header().Set("Content-Type", pl.mimeType()) 19 if etag := pl.etag(); etag != "" { 20 w.Header().Set("Etag", strconv.Quote(etag)) 21 } 22 if cacheable { 23 w.Header().Set("Expires", pl.expirationTime()) 24 } 25 readSeeker := io.NewSectionReader(content, 0, content.Size()) 26 http.ServeContent(w, r, "", pl.lastModifiedTime(), readSeeker) 27 }