Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Range HTTP Header and 206 partial content response. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,27 @@ func proxy(w http.ResponseWriter, r *http.Request) {
}
}

setTimeHeader(w, "Last-Modified", attrs.Updated)
setStrHeader(w, "Content-Type", attrs.ContentType)
setStrHeader(w, "Content-Language", attrs.ContentLanguage)
setStrHeader(w, "Cache-Control", attrs.CacheControl)
setStrHeader(w, "Content-Disposition", attrs.ContentDisposition)

gzipAcceptable := strings.Contains(r.Header.Get("Accept-Encoding"), "gzip")
objr, err := client.Bucket(attrs.Bucket).Object(attrs.Name).ReadCompressed(gzipAcceptable).NewReader(r.Context())

var objr *storage.Reader
if rangeHeader := r.Header.Get("Range"); rangeHeader != "" {
objH := client.Bucket(attrs.Bucket).Object(attrs.Name).ReadCompressed(gzipAcceptable)
serveRange(w, r, attrs.Updated, attrs.Size, objH)
return
} else {
objr, err = client.Bucket(attrs.Bucket).Object(attrs.Name).ReadCompressed(gzipAcceptable).NewReader(r.Context())
}
if err != nil {
handleError(w, err)
return
}
setTimeHeader(w, "Last-Modified", attrs.Updated)
setStrHeader(w, "Content-Type", attrs.ContentType)
setStrHeader(w, "Content-Language", attrs.ContentLanguage)
setStrHeader(w, "Cache-Control", attrs.CacheControl)
setStrHeader(w, "Content-Encoding", objr.Attrs.ContentEncoding)
setStrHeader(w, "Content-Disposition", attrs.ContentDisposition)
setIntHeader(w, "Content-Length", objr.Attrs.Size)
io.Copy(w, objr)
}
Expand Down
Loading