diff --git a/app.go b/app.go index 7f9193a1a1..5e5475b5f1 100644 --- a/app.go +++ b/app.go @@ -341,6 +341,13 @@ type Config struct { //nolint:govet // Aligning the struct fields is not necessa // Default: xml.Marshal XMLEncoder utils.XMLMarshal `json:"-"` + // XMLDecoder set by an external client of Fiber it will use the provided implementation of a + // XMLUnmarshal + // + // Allowing for flexibility in using another XML library for decoding + // Default: xml.Unmarshal + XMLDecoder utils.XMLUnmarshal `json:"-"` + // If you find yourself behind some sort of proxy, like a load balancer, // then certain header information may be sent to you using special X-Forwarded-* headers or the Forwarded header. // For example, the Host HTTP header is usually used to return the requested host. @@ -560,6 +567,9 @@ func New(config ...Config) *App { if app.config.XMLEncoder == nil { app.config.XMLEncoder = xml.Marshal } + if app.config.XMLDecoder == nil { + app.config.XMLDecoder = xml.Unmarshal + } if len(app.config.RequestMethods) == 0 { app.config.RequestMethods = DefaultMethods } diff --git a/bind.go b/bind.go index 47ef687cef..51bbebc9ea 100644 --- a/bind.go +++ b/bind.go @@ -1,8 +1,6 @@ package fiber import ( - "encoding/xml" - "github.com/gofiber/fiber/v3/binder" "github.com/gofiber/utils/v2" ) @@ -188,7 +186,7 @@ func (b *Bind) CBOR(out any) error { // XML binds the body string into the struct. func (b *Bind) XML(out any) error { bind := binder.GetFromThePool[*binder.XMLBinding](&binder.XMLBinderPool) - bind.XMLDecoder = xml.Unmarshal + bind.XMLDecoder = b.ctx.App().config.XMLDecoder // Reset & put binder defer func() { diff --git a/docs/api/fiber.md b/docs/api/fiber.md index 2c50339d50..0f2a7aa840 100644 --- a/docs/api/fiber.md +++ b/docs/api/fiber.md @@ -83,6 +83,7 @@ app := fiber.New(fiber.Config{ | WriteBufferSize | `int` | Per-connection buffer size for responses' writing. | `4096` | | WriteTimeout | `time.Duration` | The maximum duration before timing out writes of the response. The default timeout is unlimited. | `nil` | | XMLEncoder | `utils.XMLMarshal` | Allowing for flexibility in using another XML library for encoding. | `xml.Marshal` | +| XMLDecoder | `utils.XMLUnmarshal` | Allowing for flexibility in using another XML library for decoding. | `xml.Unmarshal` | ## Server listening diff --git a/docs/whats_new.md b/docs/whats_new.md index 3221f5dd5e..5e8966e468 100644 --- a/docs/whats_new.md +++ b/docs/whats_new.md @@ -49,6 +49,7 @@ We have made several changes to the Fiber app, including: - `EnablePrintRoutes` - `ListenerNetwork` (previously `Network`) - **Trusted Proxy Configuration**: The `EnabledTrustedProxyCheck` has been moved to `app.Config.TrustProxy`, and `TrustedProxies` has been moved to `TrustProxyConfig.Proxies`. +- **XMLDecoder Config Property**: The `XMLDecoder` property has been added to allow usage of 3rd-party XML libraries in XML binder. ### New Methods