http: use pattern matching instead of calling functions