@@ -3,7 +3,7 @@ package main
33import (
44 "bufio"
55 "bytes"
6- "errors "
6+ "encoding/json "
77 "fmt"
88 "io"
99 "net/http"
@@ -14,9 +14,6 @@ import (
1414 "github.com/google/gopacket/layers"
1515 "github.com/google/gopacket/reassembly"
1616 "github.com/sirupsen/logrus"
17- "google.golang.org/protobuf/proto"
18-
19- "github.com/bubble-diff/bubblecopy/pb"
2017)
2118
2219type tcpStream struct {
@@ -111,7 +108,7 @@ func handleHttp(c2s, s2c io.Reader) {
111108}
112109
113110// sendReqResp 将old req/resp发送至replay服务进行进一步处理
114- // todo: 这个函数应该是协议无关的,现在参数为http协议。
111+ // todo: 为了支持多种协议, 这个函数应该是协议无关的,现在参数为http协议。
115112func sendReqResp (req * http.Request , resp * http.Response ) (err error ) {
116113 // 序列化req/resp
117114 rawReq , err := httputil .DumpRequest (req , true )
@@ -124,37 +121,26 @@ func sendReqResp(req *http.Request, resp *http.Response) (err error) {
124121 }
125122
126123 // send them
127- request := & pb.AddRecordReq {
128- Record : & pb.Record {
129- TaskId : configuration .Taskid ,
130- OldReq : rawReq ,
131- OldResp : rawResp ,
132- NewResp : nil ,
133- },
124+ record := & Record {
125+ TaskID : configuration .Taskid ,
126+ OldReq : rawReq ,
127+ OldResp : rawResp ,
128+ NewResp : nil ,
134129 }
135- rawpb , err := proto .Marshal (request )
130+ b , err := json .Marshal (record )
136131 if err != nil {
137132 return err
138133 }
139134
140135 api := fmt .Sprintf ("http://%s%s" , configuration .ReplaySvrAddr , ApiAddRecord )
141- apiResp , err := http .Post (api , "application/octet-stream" , bytes .NewReader (rawpb ))
142- if err != nil {
143- return err
144- }
145-
146- // parse api response
147- var response pb.AddRecordResp
148- rawApiResp , err := io .ReadAll (apiResp .Body )
136+ apiResp , err := http .Post (api , "application/json" , bytes .NewReader (b ))
149137 if err != nil {
150138 return err
151139 }
152- err = proto . Unmarshal ( rawApiResp , & response )
140+ err = apiResp . Body . Close ( )
153141 if err != nil {
154- return err
155- } else if response .Code != 0 {
156- return errors .New (response .Msg )
142+ logrus .Errorf ("close AddRecord Resp.Body failed, %s" , err )
157143 }
158144
159- return apiResp . Body . Close ()
145+ return nil
160146}
0 commit comments