diff --git a/debug.go b/debug.go index 130a7b0a399..8ffafdab830 100644 --- a/debug.go +++ b/debug.go @@ -16,7 +16,7 @@ const ( Trace = 2 ) -var LogLevel int = 0 +var LogLevel int = Trace //0 var logger *log.Logger func init() { diff --git a/http_transporter.go b/http_transporter.go index 9e799ff05ca..3fa84d2c8a4 100644 --- a/http_transporter.go +++ b/http_transporter.go @@ -91,16 +91,11 @@ func (t *HTTPTransporter) SendAppendEntriesRequest(server *Server, peer *Peer, r var b bytes.Buffer json.NewEncoder(&b).Encode(req) - traceln("REQ:", b.String()) - url := fmt.Sprintf("http://%s%s", peer.Name(), t.AppendEntriesPath()) traceln(server.Name(), "POST", url) client := &http.Client{Transport: &http.Transport{DisableKeepAlives: t.DisableKeepAlives}} - httpReq, _ := http.NewRequest("POST", url, &b) - httpReq.Header.Add("Content-Type", "application/json") - - httpResp, err := client.Do(httpReq) + httpResp, err := client.Post(url, "application/json", &b) if httpResp == nil || err != nil { return nil } @@ -123,10 +118,7 @@ func (t *HTTPTransporter) SendVoteRequest(server *Server, peer *Peer, req *Reque traceln(server.Name(), "POST", url) client := &http.Client{Transport: &http.Transport{DisableKeepAlives: t.DisableKeepAlives}} - httpReq, _ := http.NewRequest("POST", url, &b) - httpReq.Header.Add("Content-Type", "application/json") - - httpResp, err := client.Do(httpReq) + httpResp, err := client.Post(url, "application/json", &b) if httpResp == nil || err != nil { return nil } diff --git a/http_transporter_test.go b/http_transporter_test.go index 2e06751c86d..ca349c1fed0 100644 --- a/http_transporter_test.go +++ b/http_transporter_test.go @@ -33,6 +33,7 @@ func TestHTTPTransporter(t *testing.T) { if servers[1].State() != Leader && servers[2].State() != Leader { t.Fatal("Expected re-election:", servers[1].State(), servers[2].State()) } + server.Initialize() server.StartFollower() } f1 := func(server *Server, httpServer *http.Server) {