aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-07-15 11:04:43 -0700
committerChris Lu <chris.lu@gmail.com>2013-07-15 11:04:43 -0700
commit70fe7e6b5d487aa72a5e5cafdab6eb3447b1fcfc (patch)
treea2f1f28c1894325894d36c7a9eac5afb0f2435ed /go
parentc6bd4e656edaf92c8a2e44f196db156d99f96f20 (diff)
downloadseaweedfs-70fe7e6b5d487aa72a5e5cafdab6eb3447b1fcfc.tar.xz
seaweedfs-70fe7e6b5d487aa72a5e5cafdab6eb3447b1fcfc.zip
support gzip file upload, fix problem during replication of gzipped data
Diffstat (limited to 'go')
-rw-r--r--go/operation/upload_content.go6
-rw-r--r--go/replication/store_replicate.go2
-rw-r--r--go/storage/needle.go6
-rw-r--r--go/weed/upload.go2
4 files changed, 11 insertions, 5 deletions
diff --git a/go/operation/upload_content.go b/go/operation/upload_content.go
index bfe2dd69b..2d6a249f2 100644
--- a/go/operation/upload_content.go
+++ b/go/operation/upload_content.go
@@ -21,12 +21,16 @@ type UploadResult struct {
Error string
}
-func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult, error) {
+func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool) (*UploadResult, error) {
body_buf := bytes.NewBufferString("")
body_writer := multipart.NewWriter(body_buf)
h := make(textproto.MIMEHeader)
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, filename))
h.Set("Content-Type", mime.TypeByExtension(strings.ToLower(filepath.Ext(filename))))
+ println("content is gzipped", isGzipped)
+ if isGzipped {
+ h.Set("Content-Encoding", "gzip")
+ }
file_writer, err := body_writer.CreatePart(h)
if err != nil {
log.Println("error creating form file", err)
diff --git a/go/replication/store_replicate.go b/go/replication/store_replicate.go
index f6e84e2ef..358f7dade 100644
--- a/go/replication/store_replicate.go
+++ b/go/replication/store_replicate.go
@@ -25,7 +25,7 @@ func ReplicatedWrite(masterNode string, s *storage.Store, volumeId storage.Volum
if needToReplicate { //send to other replica locations
if r.FormValue("type") != "replicate" {
if !distributedOperation(masterNode, s, volumeId, func(location operation.Location) bool {
- _, err := operation.Upload("http://"+location.Url+r.URL.Path+"?type=replicate&ts="+strconv.FormatUint(needle.LastModified,10), string(needle.Name), bytes.NewReader(needle.Data))
+ _, err := operation.Upload("http://"+location.Url+r.URL.Path+"?type=replicate&ts="+strconv.FormatUint(needle.LastModified,10), string(needle.Name), bytes.NewReader(needle.Data), needle.IsGzipped())
return err == nil
}) {
ret = 0
diff --git a/go/storage/needle.go b/go/storage/needle.go
index 18c4727bc..dfa7c9b26 100644
--- a/go/storage/needle.go
+++ b/go/storage/needle.go
@@ -4,8 +4,8 @@ import (
"code.google.com/p/weed-fs/go/util"
"encoding/hex"
"errors"
- "log"
"io/ioutil"
+ "log"
"mime"
"net/http"
"path"
@@ -73,7 +73,9 @@ func NewNeedle(r *http.Request) (n *Needle, e error) {
n.SetHasMime()
mtype = contentType
}
- if IsGzippable(ext, mtype) {
+ if part.Header.Get("Content-Encoding") == "gzip" {
+ n.SetGzipped()
+ } else if IsGzippable(ext, mtype) {
if data, e = GzipData(data); e != nil {
return
}
diff --git a/go/weed/upload.go b/go/weed/upload.go
index 7a72074f2..8e75b387b 100644
--- a/go/weed/upload.go
+++ b/go/weed/upload.go
@@ -78,7 +78,7 @@ func upload(filename string, server string, fid string) (int, error) {
debug("Failed to stat file:", filename)
return 0, fiErr
}
- ret, e := operation.Upload("http://"+server+"/"+fid+"?ts="+strconv.Itoa(int(fi.ModTime().Unix())), path.Base(filename), fh)
+ ret, e := operation.Upload("http://"+server+"/"+fid+"?ts="+strconv.Itoa(int(fi.ModTime().Unix())), path.Base(filename), fh, false)
if e != nil {
return 0, e
}