MessageRequest and return a changed copy. A Processor chains them to prepare a request for its next hop: add Via and Record-Route headers, point the Request-URI at the target, add or remove headers. Each alteration deep-copies the request, so the input is never mutated.
Some alterations take the request directly. Others are curried: you call them with a Route (or other arguments) first, and they return a function of the request.
Import
@routr/processor exports the alterations as Alterations and the header helpers as Extensions. The built-in Connect processor composes them with pipe from fp-ts.
mods/connect/src/tailor.ts).
Route argument is usually the result of a Location Service lookup. Its relevant fields are user, host, port, transport, advertisedHost, advertisedPort, edgePortRef, listeningPoints, localnets, externalAddrs, registeredOn, and headers.
Summary
Request-URI
fixRequestURI
host, port, and transport. When the route came from a registration (registeredOn is set) and has a user, it also sets the Request-URI user.
Via
addSelfVia
rport flag. It picks the EdgePort interface that faces the route’s target. When the route lives on the same EdgePort as the request, it uses the route’s network data; otherwise it uses the request’s.
addSelfViaUsingTheRouteHeaders
addSelfViaUsingExternalAddrs
BYE and ACK.
removeTopVia
Route
addRouteToNextHop
lr) for the route’s host, port, and transport at the top of the list. Does nothing when the Request-URI host already equals the route host.
addRouteToPeerEdgePort
listeningPoints, localnets, and externalAddrs. Use it with addXEdgePortRef when the target is connected to another EdgePort. See EdgePort cooperation.
removeSelfRoutes
Record-Route
addSelfRecordRoute
r2=on.
Headers
applyXHeaders
headers list of header modifiers. Each modifier has a name, an optional value, and an action of HeaderModifierAction.ADD or HeaderModifierAction.REMOVE. It removes every header named in a REMOVE modifier. For each ADD, it removes any existing header with that name and adds the new value. Names are matched case-insensitively.
addXEdgePortRef
X-Edgeport-Ref header with the request’s edgePortRef at the top of the extension headers. The receiving EdgePort uses it to tell the request came from a peer EdgePort. See SIP headers.
removeXEdgePortRef
X-Edgeport-Ref header, matched case-insensitively.
removeHeaders
names, matched case-insensitively. Returns the request unchanged when names is empty.
removeAuthorization
decreaseMaxForwards
Contact
fixInvalidContact
.invalid, as WebRTC clients often send, replaces it with the top Via’s received value (or host), the rport value (or port), and the Via transport.
overwriteContactWithSenderInfo
sender values, when a Contact header is present. Connect does not apply it by default.
Numbers
enforceE164
enforce is true, tries to rewrite the From, To, and Request-URI users as E.164 numbers (with a leading +). It replaces a value only when it parses as a valid number. validateMobilePrefix applies to the To and Request-URI users; the From user is always checked with mobile prefix validation. Returns the request unchanged when enforce is false.
Header helpers (Extensions)
Extensions holds helpers that read and change extension headers. Unlike alterations, they take the header data as a second argument. getHeaderValue matches names case-insensitively; the others match the exact name.
The following snippet reads a header and adds another.
Related
Build a processor
Write a Processor that uses these alterations.
Message flow
Where Processors and alterations fit in a request’s path.