Skip to content

Commit

Permalink
disable base64 encoding (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ls0f authored Mar 21, 2017
1 parent 7c109d7 commit efffcf5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
10 changes: 1 addition & 9 deletions src/proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"net"

"encoding/base64"
"io/ioutil"

"errors"
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 3 additions & 13 deletions src/proxy/local.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package proxy

import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions src/proxy/proto.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package proxy

import (
"encoding/base64"
"fmt"
"net/http"
)
Expand All @@ -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) {
Expand Down

0 comments on commit efffcf5

Please sign in to comment.