Esempio n. 1
0
func (s *Server) checkCache(r *http.Request, f *storage.File) (cont bool, status int) {
	// Check etag
	if s.conf.ETagSupport {
		if ifNoneMatch := r.Header.Get("If-None-Match"); ifNoneMatch != "" {
			if ifNoneMatch == f.ETag() {
				status = http.StatusNotModified
				return
			}
		}
	}
	// Check if modified
	if tm, err := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since")); err == nil && f.Time.Before(tm.Add(1*time.Second)) {
		status = http.StatusNotModified
		return
	}
	cont = true
	status = http.StatusOK
	return
}
Esempio n. 2
0
func (u unZip) unZipTo(to string, f *storage.File, s *storage.Storage) (filesCount, filesSize int64, err error) {

	if err = f.Open(); err != nil {
		return
	}
	defer f.Close()

	z, err := zip.NewReader(f.GetReader(), f.FSize)
	if err != nil {
		return
	}

	for _, zf := range z.File {
		if !zf.FileInfo().IsDir() {
			fs, e := u.saveFile(to, zf, s)
			if e != nil {
				err = e
				return
			}
			filesSize += fs
			filesCount++
		}
	}

	return
}