Skip to content

Switch

Switch is built on top of the mux, but instead routes a specific variable instead of the path.

Host

The Switch-Host router will route the request based on the Host header.

site.com, site.local:
router:
- !Switch-Host
- x.site.com: status 404
- hi
Request HostResult
site.comhi
x.site.com404

Path

The Switch-Path router will route the request based on the Path header.

site.com, site.local:
router:
- !Switch-Path
- /hi: status 404
- hi
Request PathResult
w.site.comhi
a.site.comhi
w.site.com/hi404
a.site.com/hi404

Method

The Switch-Method router will route the request based on the Method header.

site.com, site.local:
router:
- !Switch-Method
- POST: status 404
- hi
Request MethodResult
GEThi
POST404

Proto

The Switch-Proto router will route the request based on the protocol version of the request. This is useful for routing HTTP/2 requests differently than HTTP/1.1 requests, for instance for upgrades to WebSocket.

site.com, site.local:
router:
- !Switch-Proto
- HTTP/1.0: status 404
- hi
Request ProtoResult
HTTP/1.0404
HTTP/1.1hi
HTTP/2.0hi

UserAgent

The Switch-UserAgent router will route the request based on the User-Agent header.

site.com, site.local:
router:
- !Switch-UserAgent
- Mozilla: status 404
- hi
Request User-AgentResult
Mozilla404
Chromehi

Referer

The Switch-Referer router will route the request based on the Referer header.

site.com, site.local:
router:
- !Switch-Referer
- /hi: status 404
- hi
Request RefererResult
/hi404
/hellohi