Skip to content

Commit

Permalink
resolve sync error when using tls, closes #153 (disabled http2 suppor…
Browse files Browse the repository at this point in the history
…t until velox bug is resolved)
  • Loading branch information
jpillora committed May 5, 2017
1 parent 95ec2ce commit b9eb09e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -60,8 +61,8 @@ type Server struct {

func (s *Server) Run(version string) error {

tls := s.CertPath != "" || s.KeyPath != "" //poor man's XOR
if tls && (s.CertPath == "" || s.KeyPath == "") {
isTLS := s.CertPath != "" || s.KeyPath != "" //poor man's XOR
if isTLS && (s.CertPath == "" || s.KeyPath == "") {
return fmt.Errorf("You must provide both key and cert paths")
}

Expand Down Expand Up @@ -132,7 +133,7 @@ func (s *Server) Run(version string) error {
}
addr := fmt.Sprintf("%s:%d", host, s.Port)
proto := "http"
if tls {
if isTLS {
proto += "s"
}
if s.Open {
Expand Down Expand Up @@ -163,10 +164,18 @@ func (s *Server) Run(version string) error {
}
log.Printf("Listening at %s://%s", proto, addr)
//serve!
if tls {
return http.ListenAndServeTLS(addr, s.CertPath, s.KeyPath, h)
}
return http.ListenAndServe(addr, h)
server := http.Server{
//disable http2 due to velox bug
TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){},
//address
Addr: addr,
//handler stack
Handler: h,
}
if isTLS {
return server.ListenAndServeTLS(s.CertPath, s.KeyPath)
}
return server.ListenAndServe()
}

func (s *Server) reconfigure(c engine.Config) error {
Expand Down

0 comments on commit b9eb09e

Please sign in to comment.