Skip to content

Commit

Permalink
Merge 43fe027 into 970f99b
Browse files Browse the repository at this point in the history
  • Loading branch information
jprobinson committed Mar 21, 2016
2 parents 970f99b + 43fe027 commit 5f992f1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
language: go

before_install:
# Decrypts a script that installs an authenticated cookie
# for git to use when cloning from googlesource.com.
# Bypasses "bandwidth limit exceeded" errors.
# See github.com/golang/go/issues/12933
- openssl aes-256-cbc -K $encrypted_83935ad6c1b7_key -iv $encrypted_83935ad6c1b7_iv -in gitcookies.sh.enc -out gitcookies.sh -d
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover

install:
- bash gitcookies.sh

script:
- make test
- make coverage
Expand Down
6 changes: 6 additions & 0 deletions config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ type Server struct {
JSONContentType *string `envconfig:"GIZMO_JSON_CONTENT_TYPE"`
// MaxHeaderBytes can be used to override the default MaxHeaderBytes (1<<20).
MaxHeaderBytes *int `envconfig:"GIZMO_JSON_CONTENT_TYPE"`
// ReadTimeout can be used to override the default http server timeout of 10s.
// The string should be formatted like a time.Duration string.
ReadTimeout *string `envconfig:"GIZMO_READ_TIMEOUT"`
// WriteTimeout can be used to override the default http server timeout of 10s.
// The string should be formatted like a time.Duration string.
WriteTimeout *string `envconfig:"GIZMO_WRITE_TIMEOUT"`
// GOMAXPROCS can be used to override the default GOMAXPROCS (runtime.NumCPU).
GOMAXPROCS *int `envconfig:"GIZMO_SERVER_GOMAXPROCS"`
// HTTPAccessLog is the location of the http access log. If it is empty,
Expand Down
1 change: 1 addition & 0 deletions gitcookies.sh.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fr��u�M���av����ܦ�HL�F�I�M�4���̪�n�ьJ�LI�\��4A4]��i_����i���9�e�Z��µE��c��h��Y��-�U��Î�dk>&��=�zP(Rh$g���C�cYDO�.͌�M&l�Z�-�ý������?�q�g�����I��ަTG�'���Mi�f:*������Q�+-��>��*2��L3��Y/Rkiy�2�j8٦��ۭ���/����1f%3�|e��r �[O̜� ��'��fsK��iߵD�ҕ��W�Ȍ5�J=s�+���B�Q�s,�J7�K|0 c���К��F�� ����J�b�º��$�fܓA���ښ�E^,,-�S��=��(�?�'ז��|B�Bg��Ⱥ]E}'�k�� U��VI�
Expand Down
2 changes: 2 additions & 0 deletions server/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func (r *RPCServer) Start() error {
srv := http.Server{
Handler: RegisterAccessLogger(r.cfg, r),
MaxHeaderBytes: maxHeaderBytes,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
}
var hl net.Listener
hl, err = net.Listen("tcp", fmt.Sprintf(":%d", r.cfg.HTTPPort))
Expand Down
26 changes: 24 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ var (
Log = logrus.New()
// server is what's used in the global server funcs in the package.
server Server
// MaxHeaderBytes is used by the http server to limit the size of request headers.
// maxHeaderBytes is used by the http server to limit the size of request headers.
// This may need to be increased if accepting cookies from the public.
maxHeaderBytes = 1 << 20
// JSONContentType is the content type that will be used for JSONEndpoints.
// readTimeout is used by the http server to set a maximum duration before
// timing out read of the request. The default timeout is 10 seconds.
readTimeout = 10 * time.Second
// writeTimeout is used by the http server to set a maximum duration before
// timing out write of the response. The default timeout is 10 seconds.
writeTimeout = 10 * time.Second
// jsonContentType is the content type that will be used for JSONEndpoints.
// It will default to the web.JSONContentType value.
jsonContentType = web.JSONContentType
)
Expand Down Expand Up @@ -83,6 +89,22 @@ func Init(name string, scfg *config.Server) {
maxHeaderBytes = *scfg.MaxHeaderBytes
}

if scfg.ReadTimeout != nil {
tReadTimeout, err := time.ParseDuration(*scfg.ReadTimeout)
if err != nil {
Log.Fatal("invalid server ReadTimeout: ", err)
}
readTimeout = tReadTimeout
}

if scfg.WriteTimeout != nil {
tWriteTimeout, err := time.ParseDuration(*scfg.WriteTimeout)
if err != nil {
Log.Fatal("invalid server WriteTimeout: ", err)
}
writeTimeout = tWriteTimeout
}

// setup app logging
if scfg.Log != "" {
lf, err := logrotate.NewFile(scfg.Log)
Expand Down
2 changes: 2 additions & 0 deletions server/simple_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (s *SimpleServer) Start() error {
srv := http.Server{
Handler: RegisterAccessLogger(s.cfg, s),
MaxHeaderBytes: maxHeaderBytes,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
}

l, err := net.Listen("tcp", fmt.Sprintf(":%d", s.cfg.HTTPPort))
Expand Down

0 comments on commit 5f992f1

Please sign in to comment.