===== Routing

The javadoc:Router[setRouterOptions, io.jooby.RouterOptions] method controls routing behavior.

.Usage
[source, java, role = "primary"]
----
import io.jooby.Jooby;
...
{
  setRouterOptions(new RouterOptions()
      .setIgnoreCase(true)
      .setFailOnDuplicateRoutes(true)
      .setIgnoreTrailingSlash(true)
      .setNormalizeSlash(true)
      .setResetHeadersOnError(false)
      .setTrustProxy(true)
      .setContextAsService(true)
  );
}
----

.Kotlin
[source, kotlin, role = "secondary"]
----
import io.jooby.Jooby
...
{
  routerOptions = RouterOptions().apply {
    ignoreCase = true
    failOnDuplicateRoutes = true
    ignoreTrailingSlash = true
    normalizeSlash = true
    resetHeadersOnError = false
    trustProxy = true
    contextAsService = true
  }
}
----

[cols="1,1,1,4"]
|===
| Option | Type | Default | Description

| `contextAsService`
| boolean
| false
| If enabled, allows you to retrieve the javadoc:Context[] object associated with the current request via the service registry while the request is being processed.

| `ignoreCase`
| boolean
| false
| Indicates whether the routing algorithm uses case-sensitive matching for incoming request paths.

| `ignoreTrailingSlash`
| boolean
| false
| Indicates whether trailing slashes are ignored on incoming request paths.

| `failOnDuplicateRoutes`
| boolean
| false
| Throws an exception if multiple routes are registered with the same HTTP method and path pattern.

| `normalizeSlash`
| boolean
| false
| Normalizes incoming request paths by replacing multiple consecutive slashes with a single slash.

| `resetHeadersOnError`
| boolean
| true
| Indicates whether response headers should be cleared/reset when an exception occurs.

| `trustProxy`
| boolean
| false
| When true, parses `X-Forwarded-*` headers and updates the current context to reflect the values sent by the proxy.
|===

[IMPORTANT]
====
**trustProxy:** This should only be enabled if your application is running behind a reverse proxy configured to send `X-Forwarded-*` headers. Otherwise, remote users can spoof their IP addresses and protocols by sending malicious headers.
====
