http_svr_cfg.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package websubsvc
  2. import (
  3. "context"
  4. "crypto/tls"
  5. "log"
  6. "net"
  7. "net/http"
  8. "time"
  9. )
  10. type HttpServerConfig struct {
  11. // DisableGeneralOptionsHandler, if true, passes "OPTIONS *" requests to the Handler,
  12. // otherwise responds with 200 OK and Content-Length: 0.
  13. DisableGeneralOptionsHandler bool
  14. // TLSConfig optionally provides a TLS configuration for use
  15. // by ServeTLS and ListenAndServeTLS. Note that this value is
  16. // cloned by ServeTLS and ListenAndServeTLS, so it's not
  17. // possible to modify the configuration with methods like
  18. // tls.Config.SetSessionTicketKeys. To use
  19. // SetSessionTicketKeys, use Server.Serve with a TLS Listener
  20. // instead.
  21. TLSConfig *tls.Config
  22. // ReadTimeout is the maximum duration for reading the entire
  23. // request, including the body. A zero or negative value means
  24. // there will be no timeout.
  25. //
  26. // Because ReadTimeout does not let Handlers make per-request
  27. // decisions on each request body's acceptable deadline or
  28. // upload rate, most users will prefer to use
  29. // ReadHeaderTimeout. It is valid to use them both.
  30. ReadTimeout time.Duration
  31. // ReadHeaderTimeout is the amount of time allowed to read
  32. // request headers. The connection's read deadline is reset
  33. // after reading the headers and the Handler can decide what
  34. // is considered too slow for the body. If ReadHeaderTimeout
  35. // is zero, the value of ReadTimeout is used. If both are
  36. // zero, there is no timeout.
  37. ReadHeaderTimeout time.Duration
  38. // WriteTimeout is the maximum duration before timing out
  39. // writes of the response. It is reset whenever a new
  40. // request's header is read. Like ReadTimeout, it does not
  41. // let Handlers make decisions on a per-request basis.
  42. // A zero or negative value means there will be no timeout.
  43. WriteTimeout time.Duration
  44. // IdleTimeout is the maximum amount of time to wait for the
  45. // next request when keep-alives are enabled. If IdleTimeout
  46. // is zero, the value of ReadTimeout is used. If both are
  47. // zero, there is no timeout.
  48. IdleTimeout time.Duration
  49. // MaxHeaderBytes controls the maximum number of bytes the
  50. // server will read parsing the request header's keys and
  51. // values, including the request line. It does not limit the
  52. // size of the request body.
  53. // If zero, DefaultMaxHeaderBytes is used.
  54. MaxHeaderBytes int
  55. // TLSNextProto optionally specifies a function to take over
  56. // ownership of the provided TLS connection when an ALPN
  57. // protocol upgrade has occurred. The map key is the protocol
  58. // name negotiated. The Handler argument should be used to
  59. // handle HTTP requests and will initialize the Request's TLS
  60. // and RemoteAddr if not already set. The connection is
  61. // automatically closed when the function returns.
  62. // If TLSNextProto is not nil, HTTP/2 support is not enabled
  63. // automatically.
  64. TLSNextProto map[string]func(*http.Server, *tls.Conn, http.Handler)
  65. // ConnState specifies an optional callback function that is
  66. // called when a client connection changes state. See the
  67. // ConnState type and associated constants for details.
  68. ConnState func(net.Conn, http.ConnState)
  69. // ErrorLog specifies an optional logger for errors accepting
  70. // connections, unexpected behavior from handlers, and
  71. // underlying FileSystem errors.
  72. // If nil, logging is done via the log package's standard logger.
  73. ErrorLog *log.Logger
  74. // BaseContext optionally specifies a function that returns
  75. // the base context for incoming requests on this server.
  76. // The provided Listener is the specific Listener that's
  77. // about to start accepting requests.
  78. // If BaseContext is nil, the default is context.Background().
  79. // If non-nil, it must return a non-nil context.
  80. BaseContext func(net.Listener) context.Context
  81. // ConnContext optionally specifies a function that modifies
  82. // the context used for a new connection c. The provided ctx
  83. // is derived from the base context and has a ServerContextKey
  84. // value.
  85. ConnContext func(ctx context.Context, c net.Conn) context.Context
  86. }