@@ -306,6 +306,51 @@ type ServerConfig struct {
306306
307307 // CompressionAlgorithms configures the list of compression algorithms the server can accept. Default: ["", "gzip", "zstd", "zlib", "snappy", "deflate"]
308308 CompressionAlgorithms []string `mapstructure:"compression_algorithms"`
309+
310+ // ReadTimeout is the maximum duration for reading the entire
311+ // request, including the body. A zero or negative value means
312+ // there will be no timeout.
313+ //
314+ // Because ReadTimeout does not let Handlers make per-request
315+ // decisions on each request body's acceptable deadline or
316+ // upload rate, most users will prefer to use
317+ // ReadHeaderTimeout. It is valid to use them both.
318+ ReadTimeout time.Duration `mapstructure:"read_timeout"`
319+
320+ // ReadHeaderTimeout is the amount of time allowed to read
321+ // request headers. The connection's read deadline is reset
322+ // after reading the headers and the Handler can decide what
323+ // is considered too slow for the body. If ReadHeaderTimeout
324+ // is zero, the value of ReadTimeout is used. If both are
325+ // zero, there is no timeout.
326+ ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"`
327+
328+ // WriteTimeout is the maximum duration before timing out
329+ // writes of the response. It is reset whenever a new
330+ // request's header is read. Like ReadTimeout, it does not
331+ // let Handlers make decisions on a per-request basis.
332+ // A zero or negative value means there will be no timeout.
333+ WriteTimeout time.Duration `mapstructure:"write_timeout"`
334+
335+ // IdleTimeout is the maximum amount of time to wait for the
336+ // next request when keep-alives are enabled. If IdleTimeout
337+ // is zero, the value of ReadTimeout is used. If both are
338+ // zero, there is no timeout.
339+ IdleTimeout time.Duration `mapstructure:"idle_timeout"`
340+ }
341+
342+ // NewDefaultServerConfig returns ServerConfig type object with default values.
343+ // We encourage to use this function to create an object of ServerConfig.
344+ func NewDefaultServerConfig () ServerConfig {
345+ tlsDefaultServerConfig := configtls .NewDefaultServerConfig ()
346+ return ServerConfig {
347+ ResponseHeaders : map [string ]configopaque.String {},
348+ TLSSetting : & tlsDefaultServerConfig ,
349+ CORS : & CORSConfig {},
350+ WriteTimeout : 30 * time .Second ,
351+ ReadHeaderTimeout : 1 * time .Minute ,
352+ IdleTimeout : 1 * time .Minute ,
353+ }
309354}
310355
311356type AuthConfig struct {
@@ -437,9 +482,15 @@ func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settin
437482 includeMetadata : hss .IncludeMetadata ,
438483 }
439484
440- return & http.Server {
485+ server := & http.Server {
441486 Handler : handler ,
442- }, nil
487+ }
488+ server .ReadTimeout = hss .ReadTimeout
489+ server .ReadHeaderTimeout = hss .ReadHeaderTimeout
490+ server .WriteTimeout = hss .WriteTimeout
491+ server .IdleTimeout = hss .IdleTimeout
492+
493+ return server , nil
443494}
444495
445496func responseHeadersHandler (handler http.Handler , headers map [string ]configopaque.String ) http.Handler {
0 commit comments