diff options
Diffstat (limited to 'echo/echo_default.go')
-rw-r--r-- | echo/echo_default.go | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/echo/echo_default.go b/echo/echo_default.go index 916cbd0..98a8ee6 100644 --- a/echo/echo_default.go +++ b/echo/echo_default.go | |||
@@ -18,6 +18,7 @@ import ( | |||
18 | "github.com/labstack/echo/v4" | 18 | "github.com/labstack/echo/v4" |
19 | "github.com/labstack/echo/v4/middleware" | 19 | "github.com/labstack/echo/v4/middleware" |
20 | "github.com/labstack/gommon/log" | 20 | "github.com/labstack/gommon/log" |
21 | "github.com/quic-go/quic-go/http3" | ||
21 | ) | 22 | ) |
22 | 23 | ||
23 | // Docs: https://echo.labstack.com/guide/ | 24 | // Docs: https://echo.labstack.com/guide/ |
@@ -235,22 +236,16 @@ func (w *EchoWrapper) configureCombinedLogging(c *EchoConfig) error { | |||
235 | return nil | 236 | return nil |
236 | } | 237 | } |
237 | 238 | ||
238 | func (w *EchoWrapper) makeServerJob(s *http.Server, echoInit bool) service.RunnerFunc { | 239 | func (w *EchoWrapper) makeServerJob(s webServer) service.RunnerFunc { |
239 | return func(ctx context.Context, wg *sync.WaitGroup) error { | 240 | return func(ctx context.Context, wg *sync.WaitGroup) error { |
240 | wg.Add(1) | 241 | wg.Add(1) |
241 | defer wg.Done() | 242 | defer wg.Done() |
242 | 243 | ||
243 | w.Logger.Infof("Starting server with address: %s", s.Addr) | 244 | s.LogStart(w.Logger) |
244 | 245 | ||
245 | err := make(chan error) | 246 | err := make(chan error) |
246 | go func() { | 247 | go func() { |
247 | if s.TLSConfig == nil && echoInit { | 248 | err <- s.ListenAndServe() |
248 | err <- w.Echo.StartServer(s) | ||
249 | } else if s.TLSConfig == nil && !echoInit { | ||
250 | err <- s.ListenAndServe() | ||
251 | } else { | ||
252 | err <- s.ListenAndServeTLS("", "") | ||
253 | } | ||
254 | }() | 249 | }() |
255 | select { | 250 | select { |
256 | case e := <-err: | 251 | case e := <-err: |
@@ -267,12 +262,13 @@ func (w *EchoWrapper) makeServerJob(s *http.Server, echoInit bool) service.Runne | |||
267 | } | 262 | } |
268 | 263 | ||
269 | func (w *EchoWrapper) buildServers(c *EchoConfig, bindings *AddressPortConfig) { | 264 | func (w *EchoWrapper) buildServers(c *EchoConfig, bindings *AddressPortConfig) { |
270 | for i, a := range bindings.HttpBindings() { | 265 | for _, a := range bindings.HttpBindings() { |
271 | s := &http.Server{ | 266 | s := &http.Server{ |
272 | Addr: a, | 267 | Addr: a, |
273 | Handler: w, | 268 | Handler: w, |
269 | ErrorLog: w.StdLogger, | ||
274 | } | 270 | } |
275 | w.runner.AddJob(w.makeServerJob(s, i == 0)) | 271 | w.runner.AddJob(w.makeServerJob(&netHttpWrapper{s})) |
276 | } | 272 | } |
277 | 273 | ||
278 | for _, a := range bindings.TlsBindings() { | 274 | for _, a := range bindings.TlsBindings() { |
@@ -281,11 +277,25 @@ func (w *EchoWrapper) buildServers(c *EchoConfig, bindings *AddressPortConfig) { | |||
281 | TLSConfig: &tls.Config{ | 277 | TLSConfig: &tls.Config{ |
282 | MinVersion: tls.VersionTLS12, | 278 | MinVersion: tls.VersionTLS12, |
283 | GetCertificate: c.Autocert.GetCertificate, | 279 | GetCertificate: c.Autocert.GetCertificate, |
284 | NextProtos: []string{"h2", "http/1.1"}, // enable HTTP/2 | 280 | NextProtos: []string{"h3", "h2", "http/1.1"}, |
285 | }, | 281 | }, |
282 | Handler: w, | ||
283 | ErrorLog: w.StdLogger, | ||
284 | } | ||
285 | w.runner.AddJob(w.makeServerJob(&netHttpWrapper{s})) | ||
286 | } | ||
287 | |||
288 | for _, a := range bindings.QuicBindings() { | ||
289 | q := &http3.Server{ | ||
290 | Addr: a, | ||
291 | TLSConfig: http3.ConfigureTLSConfig(&tls.Config{ | ||
292 | MinVersion: tls.VersionTLS13, | ||
293 | GetCertificate: c.Autocert.GetCertificate, | ||
294 | }), | ||
286 | Handler: w, | 295 | Handler: w, |
287 | } | 296 | } |
288 | w.runner.AddJob(w.makeServerJob(s, false)) | 297 | w.runner.AddJob(w.makeServerJob(&http3Wrapper{q})) |
298 | w.Use(glmw.Http3AltSvcMiddleware(bindings.QuicPort)) | ||
289 | } | 299 | } |
290 | } | 300 | } |
291 | 301 | ||