Questions tagged [rust-tower]

9 questions
2
votes
1 answer

Get access to the request headers from Axum IntoResponse

I have a custom IntoResponse type that needs to return different data to the client depending on the value of the Accept header in the request. I would prefer, if possible, to have this be seamless (i.e. I don't have to pass the header value into…
wallefan
  • 354
  • 1
  • 11
2
votes
1 answer

Stateful Axum middleware not compiling if wrapped in a Mutex

I'm trying to implement a basic middleware in a Axum project, and I'm facing an issue when my middleware is passed a state wrapped in a Mutex. Disclaimer There is a high chance that the shared state used in this sample is not optimized nor…
Rafi Panoyan
  • 822
  • 9
  • 21
2
votes
0 answers

Function to create GRPC server with generic protobuf service and generic tower layer parameters

I'm writing a function fn run_grpc_server(service: S, layer: L) -> Result<(), String> where I need to provide generic parameter for protobuf service S and tower layer L, so I can build the GRPC server combining them. To illustrate, I modify…
bits
  • 1,595
  • 1
  • 17
  • 17
2
votes
2 answers

Axum router rejecting CORS OPTIONS preflight with 405 even with CorsLayer

Before a fetch is sent, the browser will send a request method OPTIONS to confirm that the API will accept the request from a script with a particular origin. Chrome shows that the my Axum server is rejecting my client's request with 405. My router…
Alister Lee
  • 2,236
  • 18
  • 21
2
votes
2 answers

Is there a way to bind a variable to a request in tower-http / hyper / axum?

I'm trying to add a request id to each tracing event. I can do it with tower_http::trace like this: #[derive(Clone)] pub struct RequestSpan; impl tower_http::trace::MakeSpan for RequestSpan { fn make_span(&mut self, request:…
imbolc
  • 1,620
  • 1
  • 19
  • 32
1
vote
2 answers

Use hyper to pass IP address of incoming connection to stack of Services

I am trying to write a server using hyper that will pass the remote (client) address of the incoming connection down to a stack of Layers (that I have built using ServiceBuilder. I have tried to use examples from the hyper docs and also this example…
d2718
  • 175
  • 8
1
vote
1 answer

How to configure tower_http TraceLayer in a separate function?

I'm implementing a tokio/axum HTTP server. In the function where I run the server, I configure routing, add shared application services and add tracing layer. My tracing configuration looks like this: let tracing_layer = TraceLayer::new_for_http() …
iTollu
  • 999
  • 13
  • 20
0
votes
1 answer

Implement tower::Layer using async block and ServiceFn

I'm trying to implement a tower Layer using the tower::layer_fn and tower::service_fn helper functions like this (compiles fine): use std::convert::Infallible; use tower::Service; use tower::util::ServiceFn; tower::ServiceBuilder::new() …
linuskmr
  • 727
  • 3
  • 13
-1
votes
1 answer

no method named `incoming` found for struct `tokio::net::TcpListener`

I am writing a tcp echo server using tower and tokio. However, I am unable to use the method incoming for tokio::net::TcpListener /* [dependencies] futures = "0.3" tokio = { version = "1", features = ["full"] } tower = { version = "0.4", features =…
Blank
  • 423
  • 1
  • 5
  • 16