diff --git a/src/proxy/http.go b/src/proxy/http.go index 6dafaa0..ce20fff 100644 --- a/src/proxy/http.go +++ b/src/proxy/http.go @@ -9,7 +9,6 @@ import ( "fmt" "net" - "encoding/base64" "io/ioutil" "errors" @@ -156,14 +155,7 @@ func (hp *httpProxy) push(w http.ResponseWriter, r *http.Request) { WriteHTTPError(w, fmt.Sprintf("read err:%v", err)) return } - decodeLen := base64.StdEncoding.DecodedLen(len(body)) - buf := make([]byte, decodeLen) - n, err := base64.StdEncoding.Decode(buf, []byte(body)) - if err != nil { - WriteHTTPError(w, fmt.Sprintf("b64 decode err:%v", err)) - return - } - d = dataBodyTyp{typ: DATA_TYP, body: buf[:n]} + d = dataBodyTyp{typ: DATA_TYP, body: body} } select { diff --git a/src/proxy/local.go b/src/proxy/local.go index 7350a08..6dafd5d 100644 --- a/src/proxy/local.go +++ b/src/proxy/local.go @@ -1,7 +1,6 @@ package proxy import ( - "encoding/base64" "errors" "fmt" "io/ioutil" @@ -44,10 +43,11 @@ func (c *localProxyConn) gen_sign(req *http.Request) { func (c *localProxyConn) push(data []byte, typ string) error { hc := &http.Client{Transport: tr, Timeout: time.Duration(time.Second * heartTTL)} - buf := bufio.NewBufferString(base64.StdEncoding.EncodeToString(data)) + buf := bufio.NewBuffer(data) req, _ := http.NewRequest("POST", c.server+PUSH, buf) c.gen_sign(req) req.Header.Set("TYP", typ) + req.Header.Set("Content-Type", "image/jpeg") res, err := hc.Do(req) if err != nil { return err @@ -60,7 +60,6 @@ func (c *localProxyConn) push(data []byte, typ string) error { default: return errors.New(fmt.Sprintf("status code is %d, body is: %s", res.StatusCode, string(body))) } - return nil } func (c *localProxyConn) connect(dstHost, dstPort string) (uuid string, err error) { @@ -129,16 +128,7 @@ func (c *localProxyConn) fill() error { if err != nil { return err } - data := string(data_bytes) - - decodeLen := base64.StdEncoding.DecodedLen(len(data)) - bData := make([]byte, len(c.read_buffer)+decodeLen) - n, err := base64.StdEncoding.Decode(bData[len(c.read_buffer):], data_bytes) - if err != nil { - return err - } - bData = bData[:len(c.read_buffer)+n] - c.read_buffer = bData + c.read_buffer = append(c.read_buffer, data_bytes...) return nil } diff --git a/src/proxy/proto.go b/src/proxy/proto.go index da855b8..73761a5 100644 --- a/src/proxy/proto.go +++ b/src/proxy/proto.go @@ -1,7 +1,6 @@ package proxy import ( - "encoding/base64" "fmt" "net/http" ) @@ -26,8 +25,8 @@ func WriteHTTPOK(w http.ResponseWriter, data string) { func WriteHTTPData(w http.ResponseWriter, data []byte) { w.WriteHeader(HeadData) - data_encoded := base64.StdEncoding.EncodeToString(data) - fmt.Fprintf(w, "%s", data_encoded) + w.Header().Set("Content-Type", "image/jpeg") + w.Write(data) } func WriteHTTPQuit(w http.ResponseWriter, data string) {