Skip to content

Commit

Permalink
Addressed review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
anivanovic committed Oct 24, 2023
1 parent 534a193 commit 812fdac
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ type ServiceConfig struct {
// the router layer
TLS *TLS `mapstructure:"tls"`

// UseH2C enables h2c support.
UseH2C bool `json:"use_h2c"`

// run lura in debug mode
Debug bool `mapstructure:"debug_endpoint"`
Echo bool `mapstructure:"echo_endpoint"`
Expand Down
1 change: 1 addition & 0 deletions router/gin/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func NewEngine(cfg config.ServiceConfig, opt EngineOptions) *gin.Engine {
engine.AppEngine = ginOptions.AppEngine
engine.MaxMultipartMemory = ginOptions.MaxMultipartMemory
engine.RemoveExtraSlash = ginOptions.RemoveExtraSlash
engine.UseH2C = ginOptions.UseH2C
paths = ginOptions.LoggerSkipPaths

returnErrorMsg = ginOptions.ReturnErrorMsg
Expand Down
20 changes: 2 additions & 18 deletions transport/http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -41,8 +40,6 @@ const (
// HeaderIncompleteResponseValue is the value of the CompleteResponseHeader
// if the response is not complete
HeaderIncompleteResponseValue = "false"
// ginNamespace used to grab router extra config
ginNamespace = "github_com/luraproject/lura/router/gin"
)

var (
Expand Down Expand Up @@ -144,22 +141,9 @@ func NewServer(cfg config.ServiceConfig, handler http.Handler) *http.Server {
return NewServerWithLogger(cfg, handler, nil)
}

type serverOptions struct {
// UseH2C enable h2c support.
UseH2C bool `json:"use_h2c"`
}

func NewServerWithLogger(cfg config.ServiceConfig, handler http.Handler, logger logging.Logger) *http.Server {
// wrap handler with h2c handler if it is enabled
srvCfg := serverOptions{}
if v, ok := cfg.ExtraConfig[ginNamespace]; ok {
if d, err := json.Marshal(v); err == nil {
if err := json.Unmarshal(d, &srvCfg); err == nil {
if srvCfg.UseH2C {
handler = h2c.NewHandler(handler, &http2.Server{})
}
}
}
if cfg.UseH2C {
handler = h2c.NewHandler(handler, &http2.Server{})
}

return &http.Server{
Expand Down

0 comments on commit 812fdac

Please sign in to comment.