Final-Length header
This commit is contained in:
parent
18cffb2b03
commit
8b1a251f6f
|
@ -24,7 +24,7 @@ func newDataStore(dir string, maxSize int64) *DataStore {
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataStore) CreateFile(id string, size int64, contentType string, contentDisposition string) error {
|
func (s *DataStore) CreateFile(id string, size int64, meta map[string]string) error {
|
||||||
file, err := os.OpenFile(s.filePath(id), os.O_CREATE|os.O_WRONLY, 0666)
|
file, err := os.OpenFile(s.filePath(id), os.O_CREATE|os.O_WRONLY, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -33,8 +33,8 @@ func (s *DataStore) CreateFile(id string, size int64, contentType string, conten
|
||||||
|
|
||||||
entry := logEntry{Meta: &metaEntry{
|
entry := logEntry{Meta: &metaEntry{
|
||||||
Size: size,
|
Size: size,
|
||||||
ContentType: contentType,
|
ContentType: "",
|
||||||
ContentDisposition: contentDisposition,
|
ContentDisposition: "",
|
||||||
}}
|
}}
|
||||||
return s.appendFileLog(id, entry)
|
return s.appendFileLog(id, entry)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,6 +90,19 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (h *Handler) createFile(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) createFile(w http.ResponseWriter, r *http.Request) {
|
||||||
id := uid()
|
id := uid()
|
||||||
|
|
||||||
|
finalLength, err := strconv.ParseInt(r.Header.Get("Final-Length"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
err = errors.New("invalid Final-Length header: "+err.Error())
|
||||||
|
h.err(err, w, http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.store.CreateFile(id, finalLength, nil); err != nil {
|
||||||
|
h.err(err, w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Set("Location", h.absUrl(r, "/"+id))
|
w.Header().Set("Location", h.absUrl(r, "/"+id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +111,8 @@ func (h *Handler) createFile(w http.ResponseWriter, r *http.Request) {
|
||||||
//
|
//
|
||||||
// @TODO: Look at r.TLS to determine the url scheme.
|
// @TODO: Look at r.TLS to determine the url scheme.
|
||||||
// @TODO: Make url prefix user configurable (optional) to deal with reverse
|
// @TODO: Make url prefix user configurable (optional) to deal with reverse
|
||||||
// proxies.
|
// proxies. This could be done by turning BasePath into BaseURL that
|
||||||
|
// that could be relative or absolute.
|
||||||
func (h *Handler) absUrl(r *http.Request, relPath string) string {
|
func (h *Handler) absUrl(r *http.Request, relPath string) string {
|
||||||
return "http://" + r.Host + path.Clean(h.config.BasePath+relPath)
|
return "http://" + r.Host + path.Clean(h.config.BasePath+relPath)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue