Skip to content

Commit ab8c805

Browse files
authored
Merge pull request #286 from devfeel/aicode
Aicode
2 parents 16e7808 + 458f83d commit ab8c805

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

config/configs.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ type (
3737

3838
// ServerNode dotweb app's httpserver config
3939
ServerNode struct {
40-
EnabledListDir bool `xml:"enabledlistdir,attr"` // enable listing of directories, only valid for Router.ServerFile, default is false
41-
EnabledRequestID bool `xml:"enabledrequestid,attr"` // enable uniq request ID, default is false, 32-bit UUID is used if enabled
42-
EnabledGzip bool `xml:"enabledgzip,attr"` // enable gzip
43-
EnabledAutoHEAD bool `xml:"enabledautohead,attr"` // ehanble HEAD routing, default is false, will add HEAD routing for all routes except for websocket and HEAD
44-
EnabledAutoOPTIONS bool // enable OPTIONS routing, default is false, will add OPTIONS routing for all routes except for websocket and OPTIONS
45-
EnabledIgnoreFavicon bool `xml:"enabledignorefavicon,attr"` // ignore favicon.ico request, return empty reponse if set
46-
EnabledBindUseJsonTag bool `xml:"enabledbindusejsontag,attr"` // allow Bind to use JSON tag, default is false, Bind will use json tag automatically and ignore form tag
47-
EnabledStaticFileMiddleware bool // The flag which enabled or disabled middleware for static-file route
40+
EnabledListDir bool `xml:"enabledlistdir,attr"` // enable listing of directories, only valid for Router.ServerFile, default is false
41+
EnabledRequestID bool `xml:"enabledrequestid,attr"` // enable uniq request ID, default is false, 32-bit UUID is used if enabled
42+
EnabledGzip bool `xml:"enabledgzip,attr"` // enable gzip
43+
EnabledAutoHEAD bool `xml:"enabledautohead,attr"` // ehanble HEAD routing, default is false, will add HEAD routing for all routes except for websocket and HEAD
44+
EnabledAutoOPTIONS bool `xml:"-"` // enable OPTIONS routing, default is false, will add OPTIONS routing for all routes except for websocket and OPTIONS
45+
EnabledRedirectTrailingSlash bool `xml:"enabledredirecttrailingslash,attr"` // enable automatic redirection for URLs with trailing slash, default is false to match net/http behavior
46+
EnabledIgnoreFavicon bool `xml:"enabledignorefavicon,attr"` // ignore favicon.ico request, return empty reponse if set
47+
EnabledBindUseJsonTag bool `xml:"enabledbindusejsontag,attr"` // allow Bind to use JSON tag, default is false, Bind will use json tag automatically and ignore form tag
48+
EnabledStaticFileMiddleware bool `xml:"-"` // The flag which enabled or disabled middleware for static-file route
4849
Port int `xml:"port,attr"` // port
4950
EnabledTLS bool `xml:"enabledtls,attr"` // enable TLS
5051
TLSCertFile string `xml:"tlscertfile,attr"` // certifications file for TLS

dotweb.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,14 @@ func DefaultMethodNotAllowedHandler(ctx Context) {
705705

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

router.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,16 @@ func (ps Params) ByName(name string) string {
155155
// New returns a new initialized Router.
156156
// Path auto-correction, including trailing slashes, is enabled by default.
157157
func NewRouter(server *HttpServer) *router {
158+
// Use ServerConfig.EnabledRedirectTrailingSlash if set, otherwise default to false
159+
// to match net/http behavior (Issue #245)
160+
// Note: During initialization, ServerConfig may be nil, so we check for that
161+
redirectTrailingSlash := false
162+
if server != nil && server.DotApp != nil && server.DotApp.Config != nil && server.DotApp.Config.Server != nil {
163+
redirectTrailingSlash = server.ServerConfig().EnabledRedirectTrailingSlash
164+
}
165+
158166
return &router{
159-
RedirectTrailingSlash: true,
167+
RedirectTrailingSlash: redirectTrailingSlash,
160168
RedirectFixedPath: true,
161169
HandleOPTIONS: true,
162170
allRouterExpress: make(map[string]struct{}),

0 commit comments

Comments
 (0)