Switch to Range header

This commit is contained in:
Felix Geisendörfer 2013-03-18 16:51:24 +01:00
parent 137ab8afa4
commit 6f19077d2d
3 changed files with 11 additions and 31 deletions

View File

@ -129,16 +129,16 @@ Host: tus.example.com
HTTP/1.1 200 Ok
Content-Length: 100
Content-Type: image/jpg
X-Missing: bytes=20-50,60-99
Range: bytes=0-20,40-99
```
The `X-Missing` header holds a [byte
The `Range` header holds a [byte
range](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1) that
informs the client which parts of the file have not been received yet. It is
informs the client which parts of the file have been received so far. It is
up to the client to choose appropiate `PUT` requests to complete the upload.
The absence of a `X-Missing` header means that the the entire file has been
received by the server.
A completed upload will be indicated by a single range covering the entire file
size (e.g. `Range: bytes=0-99` for a 100 byte file).
### GET \<fileUrl\>

View File

@ -123,23 +123,3 @@ func getReceivedChunks(fileId string) (chunkSet, error) {
return chunks, nil
}
func getMissingChunks(fileId string) (chunkSet, error) {
d := dataPath(fileId)
stat, err := os.Stat(d)
if err != nil {
return nil, err
}
receivedChunks, err := getReceivedChunks(fileId)
if err != nil {
return nil, err
}
// @TODO actually calcuate missing chunks instead of received
_ = stat
//chunks := chunkSet{{Start: 0, End: stat.Size()-1}}
//chunks := make(chunkSet, 0)
return receivedChunks, nil
}

View File

@ -102,21 +102,21 @@ func putFile(w http.ResponseWriter, r *http.Request, fileId string) {
}
func headFile(w http.ResponseWriter, r *http.Request, fileId string) {
chunks, err := getMissingChunks(fileId)
chunks, err := getReceivedChunks(fileId)
if err != nil {
reply(w, http.StatusInternalServerError, err.Error())
return
}
missing := ""
received := ""
for i, chunk := range chunks {
missing += fmt.Sprintf("%d-%d", chunk.Start, chunk.End)
received += fmt.Sprintf("%d-%d", chunk.Start, chunk.End)
if i + 1 < len(chunks) {
missing += ","
received += ","
}
}
if missing != "" {
w.Header().Set("X-Missing", "bytes="+missing)
if received != "" {
w.Header().Set("Range", "bytes="+received)
}
}