Listener and route — bind and match
A listener is the socket the proxy binds (an address+port); a route is one row in an ordered match table — the first row that matches decides the destination, so order is meaning, not decoration.
Reading method and path is only useful if the proxy has a structured table that says 'this kind of request goes there' — and that table is two named pieces: a listener and a route.
Scene 04
Listener and route — bind and match
- Watch
- Try it
- Predict
- Capture
A test request GET /checkout/cart (with header x-canary: true) hits the listener on port 8080. The proxy walks the route table top-to-bottom. The first matching row glows green and the request exits toward its named destination.
Highlighted lines are the ones running in the diagram right now.
def bind_listener(cfg):sock = listen(addr=cfg.address, port=cfg.port)# filter chain: TLS? HTTP? raw TCP? — picks HCM here.chain = [http_connection_manager(routes=cfg.routes)]while conn := sock.accept():chain.handle(conn) # parse req, then route_match
def match(req, routes):for route in routes: # ORDERED — RDS order is policyif matches(req, route.match):return route.destinationreturn DEFAULT_REJECT # 404 / direct_responsedef matches(req, m):if m.kind == 'wildcard': return Trueif m.kind == 'prefix': return req.path.startswith(m.value)if m.kind == 'header':name, want = m.value.split(':', 1)return req.headers.get(name.strip()) == want.strip()
# ordering 0: wildcard on top[wildcard '/*', prefix '/checkout', header 'x-canary'] -> default-svc# ordering 1: prefix on top (canary unreachable below)[prefix '/checkout', header 'x-canary', wildcard '/*'] -> checkout-v1# ordering 2: header on top (canary works)[header 'x-canary', prefix '/checkout', wildcard '/*'] -> checkout-v2
Where this sits in Build a Service Mesh (Envoy / Istio style)
Scene 04 of 13. A listener accepts on a port; an ordered route table picks a destination on the first match. Reorder the rules and the same request lands somewhere else.
Up next. A route's destination is a name like checkout-svc, but behind that name are many replicas — and the proxy has to pick one for every request.
All 13 scenes in Build a Service Mesh (Envoy / Istio style) · Every curriculum