Switch to Range header
This commit is contained in:
parent
137ab8afa4
commit
6f19077d2d
10
README.md
10
README.md
|
@ -129,16 +129,16 @@ Host: tus.example.com
|
||||||
HTTP/1.1 200 Ok
|
HTTP/1.1 200 Ok
|
||||||
Content-Length: 100
|
Content-Length: 100
|
||||||
Content-Type: image/jpg
|
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
|
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.
|
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
|
A completed upload will be indicated by a single range covering the entire file
|
||||||
received by the server.
|
size (e.g. `Range: bytes=0-99` for a 100 byte file).
|
||||||
|
|
||||||
### GET \<fileUrl\>
|
### GET \<fileUrl\>
|
||||||
|
|
||||||
|
|
|
@ -123,23 +123,3 @@ func getReceivedChunks(fileId string) (chunkSet, error) {
|
||||||
|
|
||||||
return chunks, nil
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -102,21 +102,21 @@ func putFile(w http.ResponseWriter, r *http.Request, fileId string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func headFile(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 {
|
if err != nil {
|
||||||
reply(w, http.StatusInternalServerError, err.Error())
|
reply(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
missing := ""
|
received := ""
|
||||||
for i, chunk := range chunks {
|
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) {
|
if i + 1 < len(chunks) {
|
||||||
missing += ","
|
received += ","
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if missing != "" {
|
if received != "" {
|
||||||
w.Header().Set("X-Missing", "bytes="+missing)
|
w.Header().Set("Range", "bytes="+received)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue