-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions for setting default custom handlers? #801
Comments
Hi @findmyway, thanks for opening an issue. Can you explain a little more what your use-case is? Here's a few thoughts:
I think we could build up a few more of these convenient middlewares that are defined in the Handlers module. Once we have those, we could think about doing something similar to the client-side, where we have a |
Hi @quinnj , I was planed to extract trace context from the headers and inject it into the current task local storage. So without a place to default custom handlers, users have to add such handler for every route explicitly. This may be error-prone. |
The way I would handle this in the new framework (I know this is still just HTTP#master, but we're trying to get the new breaking release out soon), is to define a tracing middleware, something like: function tracing_context_middleware(handler)
function (req)
if hasheader(req, "traceparent")
req.context[:traceparent] = header(req, "traceparent")
end
if hasheader(req, "tracestate")
req.context[:tracestate] = header(req, "tracestate")
end
return handler(req)
end
end We can then compose this with a Router and running our server by doing something like: const router = HTTP.Router()
HTTP.register!(router, "GET", "/api/config/values")
HTTP.serve(tracing_context_middleware(router), "0.0.0.0", 8081) So note that the I'm planning on overhauling all the docs soonish, so this might end up being an example of how to write a custom middleware and how it composes with handlers when setting up a server. [EDIT]: and just to close the loop on your recent comment: note how every request will first pass through the |
Thanks for the detailed explaination!
I see, that's pretty concise. |
Great! I'll close this issue for now, but watch for a big documentation update coming here soon to help walk through the new frameworks for HTTP.jl 1.0. |
Hi @quinnj , While looking into the latest code, I find the concept of However, AFAIK, the default middleware of each |
Similar to #608, is it possible to allow setting default custom handlers for both
listen
andserve
?The text was updated successfully, but these errors were encountered: