Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions config/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ type (

// ServerNode dotweb app's httpserver config
ServerNode struct {
EnabledListDir bool `xml:"enabledlistdir,attr"` // enable listing of directories, only valid for Router.ServerFile, default is false
EnabledRequestID bool `xml:"enabledrequestid,attr"` // enable uniq request ID, default is false, 32-bit UUID is used if enabled
EnabledGzip bool `xml:"enabledgzip,attr"` // enable gzip
EnabledAutoHEAD bool `xml:"enabledautohead,attr"` // ehanble HEAD routing, default is false, will add HEAD routing for all routes except for websocket and HEAD
EnabledAutoOPTIONS bool // enable OPTIONS routing, default is false, will add OPTIONS routing for all routes except for websocket and OPTIONS
EnabledIgnoreFavicon bool `xml:"enabledignorefavicon,attr"` // ignore favicon.ico request, return empty reponse if set
EnabledBindUseJsonTag bool `xml:"enabledbindusejsontag,attr"` // allow Bind to use JSON tag, default is false, Bind will use json tag automatically and ignore form tag
EnabledStaticFileMiddleware bool // The flag which enabled or disabled middleware for static-file route
EnabledListDir bool `xml:"enabledlistdir,attr"` // enable listing of directories, only valid for Router.ServerFile, default is false
EnabledRequestID bool `xml:"enabledrequestid,attr"` // enable uniq request ID, default is false, 32-bit UUID is used if enabled
EnabledGzip bool `xml:"enabledgzip,attr"` // enable gzip
EnabledAutoHEAD bool `xml:"enabledautohead,attr"` // ehanble HEAD routing, default is false, will add HEAD routing for all routes except for websocket and HEAD
EnabledAutoOPTIONS bool `xml:"-"` // enable OPTIONS routing, default is false, will add OPTIONS routing for all routes except for websocket and OPTIONS
EnabledRedirectTrailingSlash bool `xml:"enabledredirecttrailingslash,attr"` // enable automatic redirection for URLs with trailing slash, default is false to match net/http behavior
EnabledIgnoreFavicon bool `xml:"enabledignorefavicon,attr"` // ignore favicon.ico request, return empty reponse if set
EnabledBindUseJsonTag bool `xml:"enabledbindusejsontag,attr"` // allow Bind to use JSON tag, default is false, Bind will use json tag automatically and ignore form tag
EnabledStaticFileMiddleware bool `xml:"-"` // The flag which enabled or disabled middleware for static-file route
Port int `xml:"port,attr"` // port
EnabledTLS bool `xml:"enabledtls,attr"` // enable TLS
TLSCertFile string `xml:"tlscertfile,attr"` // certifications file for TLS
Expand Down
2 changes: 1 addition & 1 deletion consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dotweb
// Global define
const (
// Version current version
Version = "1.7.3"
Version = "1.8"
)

// Log define
Expand Down
7 changes: 7 additions & 0 deletions dotweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,14 @@ func DefaultMethodNotAllowedHandler(ctx Context) {

// DefaultAutoOPTIONSHandler default handler for options request
// if set HttpServer.EnabledAutoOPTIONS, auto bind this handler
// Sets CORS headers to support cross-origin preflight requests (Issue #250)
func DefaultAutoOPTIONSHandler(ctx Context) error {
// Set CORS headers for preflight requests
h := ctx.Response().Header()
h.Set("Access-Control-Allow-Origin", "*")
h.Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
h.Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With")
h.Set("Access-Control-Max-Age", "86400")
return ctx.WriteStringC(http.StatusNoContent, "")
}

Expand Down
10 changes: 9 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,16 @@ func (ps Params) ByName(name string) string {
// New returns a new initialized Router.
// Path auto-correction, including trailing slashes, is enabled by default.
func NewRouter(server *HttpServer) *router {
// Use ServerConfig.EnabledRedirectTrailingSlash if set, otherwise default to false
// to match net/http behavior (Issue #245)
// Note: During initialization, ServerConfig may be nil, so we check for that
redirectTrailingSlash := false
if server != nil && server.DotApp != nil && server.DotApp.Config != nil && server.DotApp.Config.Server != nil {
redirectTrailingSlash = server.ServerConfig().EnabledRedirectTrailingSlash
}

return &router{
RedirectTrailingSlash: true,
RedirectTrailingSlash: redirectTrailingSlash,
RedirectFixedPath: true,
HandleOPTIONS: true,
allRouterExpress: make(map[string]struct{}),
Expand Down