mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
Gzip data for upload
Relevant issue: #121 This tiny PR gzips the body of the POST request before uploading it, and adds the appropriate `Accept-Encoding` header to the request. As far as I can tell, no change needs to be made on the Rails end, since `Net:HTTP` knows to automatically decompress gzipped requests if they contain the `Accept-Encoding: gzip` header. I tested this by compiling locally and uploading a session ([](https://asciinema.org/a/5a4ro8drmyekusbrzbrt3n5ur)) and it seemed to work.
This commit is contained in:
11
api/api.go
11
api/api.go
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -74,7 +75,8 @@ func (a *AsciinemaAPI) urlForUpload() string {
|
||||
|
||||
func (a *AsciinemaAPI) headersForUpload() map[string]string {
|
||||
return map[string]string{
|
||||
"User-Agent": fmt.Sprintf("asciinema/%s %s/%s %s-%s", a.version, runtime.Compiler, runtime.Version(), runtime.GOOS, runtime.GOARCH),
|
||||
"User-Agent": fmt.Sprintf("asciinema/%s %s/%s %s-%s", a.version, runtime.Compiler, runtime.Version(), runtime.GOOS, runtime.GOARCH),
|
||||
"Content-Encoding": "gzip",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +86,12 @@ func filesForUpload(path string) (map[string]io.ReadCloser, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return map[string]io.ReadCloser{"asciicast:asciicast.json": file}, nil
|
||||
zippedFile, err := gzip.NewReader(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return map[string]io.ReadCloser{"asciicast:asciicast.json": zippedFile}, nil
|
||||
}
|
||||
|
||||
func extractWarningMessage(response *http.Response) string {
|
||||
|
||||
Reference in New Issue
Block a user