Skip to content
Permalink
Browse files

Add easy way to set Read/WriteTimeout instead of http://targetliu.com…

…/golang-iriszhong-tong-guo-pluginshe-zhi-httpchao-shi-shi-jian/

Instead of this article, I just found, shows you how to inject the main
server, now you can just use the:
iris.ListenTo(config.Server{WriteTimeout: 5* time.Second, ReadTimeout=
5*time.Second, ListeningAddr:":8080"})
  • Loading branch information...
Gerasimos Maropoulos
Gerasimos Maropoulos committed Aug 5, 2016
1 parent 2b36481 commit 3c50d26808461e8f28b66e99bb6511a875e8cfb5
Showing with 16 additions and 1 deletion.
  1. +14 −0 config/server.go
  2. +2 −1 http.go
@@ -4,6 +4,7 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/imdario/mergo"
"github.com/valyala/fasthttp"
@@ -75,6 +76,19 @@ type Server struct {
// Default buffer size is used if not set.
WriteBufferSize int

// Maximum duration for reading the full request (including body).
//
// This also limits the maximum duration for idle keep-alive
// connections.
//
// By default request read timeout is unlimited.
ReadTimeout time.Duration

// Maximum duration for writing the full response (including body).
//
// By default response write timeout is unlimited.
WriteTimeout time.Duration

// RedirectTo, defaults to empty, set it in order to override the station's handler and redirect all requests to this address which is of form(HOST:PORT or :PORT)
//
// NOTE: the http status is 'StatusMovedPermanently', means one-time-redirect(the browser remembers the new addr and goes to the new address without need to request something from this server
@@ -434,7 +434,8 @@ func (s *Server) Open(h fasthttp.RequestHandler) error {
s.Server.MaxRequestBodySize = s.Config.MaxRequestBodySize
s.Server.ReadBufferSize = s.Config.ReadBufferSize
s.Server.WriteBufferSize = s.Config.WriteBufferSize

s.Server.ReadTimeout = s.Config.ReadTimeout
s.Server.WriteTimeout = s.Config.WriteTimeout
if s.Config.RedirectTo != "" {
// override the handler and redirect all requests to this addr
s.Server.Handler = func(reqCtx *fasthttp.RequestCtx) {

1 comment on commit 3c50d26

@TargetLiu

This comment has been minimized.

Copy link

commented on 3c50d26 Aug 5, 2016

I'm very surprised that you can notice my article.
I am a beginner of GO and iris.
I just record some notes in my blog.
I'm going to correct my method and update this article.

Please sign in to comment.
You can’t perform that action at this time.