Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 03:31
    codecov[bot] commented #1797
  • 03:25
    codecov[bot] commented #1797
  • 02:54
    robjtede edited #1797
  • 02:54
    robjtede edited #1797
  • 02:54
    robjtede synchronize #1797
  • 02:54

    robjtede on quality

    update changelog (compare)

  • 02:52
    robjtede review_requested #1797
  • 02:52
    robjtede labeled #1797
  • 02:52
    robjtede labeled #1797
  • 02:52
    robjtede opened #1797
  • 02:47

    robjtede on quality

    refactor quality and use TryFro… (compare)

  • 02:46

    robjtede on quality

    (compare)

  • 01:11
    robjtede deleted #1796
  • 01:11
    robjtede closed #1796
  • 01:10
    codecov[bot] commented #1793
  • 01:01
    robjtede commented #1796
  • 00:52
    d00z3l opened #1796
  • 00:37
    robjtede synchronize #1793
  • 00:37

    robjtede on accept-precedence

    add method for getting accept t… (compare)

  • 00:31

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ 2… (compare)

neilyoung
@neilyoung
@robjtede Hi Rob, nice to meet you again. The problem is just marginally and I worked around by disabling a warning.
neilyoung
@neilyoung
I was trying to utilize the HttpServer::stop function. I saved a reference to my earlier created "Server" in a global singleton state, which I picked up on receipt of a "terminate" command via my REST API. While issuing the command from my route handler I'm seeing a warning in the compiler (which is correct I guess): "unused implementer of std::future::Future that must be used" - for this call: http_server.unwrap().stop(true);. The nice thing is: The stop works and it does not work if I put it all into an async fn and wait for it... So I disabled the linter warning and was fine.
33 replies
Not sure if I should be concerned...
gitmko0
@gitmko0
LiteSpeed Web ADC is too expensive. I'm looking at actix-web as an alternative solution.
Anyone developing actix-web with automatic ssl using letsencrypt / certbot + able to do loadbalancing? hash by ip
neilyoung
@neilyoung
@robjtede Hi Rob, the number of actix samples is kind of overwhelming (https://github.com/actix/examples). I would need a minimalistic secure HTTP GET/POST/PUT/DELETE async sample. Is there some you could recommend out of the box?
... as client
6 replies
neilyoung
@neilyoung
Looks good. Thanks. Came across this sample https://docs.rs/actix-web/0.7.17/actix_web/client/index.html. It does not work the way it is shown. Just as info.
81 replies
neilyoung
@neilyoung

I'm using log4rs in conjunction with actix and I really have a hard time to prevent actix from logging. My "solution" right now is to set all known trace sources to "error", this helps at least to not get a completely messed log. But is is very cumbersome, since not all sources of trace are known beforehand, so I have to add more and more filters.

                .logger(Logger::builder().build("actix_server::builder", LevelFilter::Error))
                .logger(Logger::builder().build("actix_http::h1::decoder", LevelFilter::Error))

Is there any known more generic solution to disable logging for actix entirely?

2 replies
rkfox
@rkfox
Is there a default maximum POST size?
I don't have an issue posting 128kb slices, but actix does not receive anything if I go to a higher number like 256kb or 512kb.
19 replies
Adam Chalmers
@adamchalmers
When a handler can't deserialize a HTTP request body into the specified type (via Serde), the handler responds with HTTP 400 and an empty body. Is there any way to include the Serde error in the response body?
2 replies
Rishav Sharan
@rishavs

Hi. Just started with Rust and am trying to work with actix and sqlx. Is this the proper way to share a db connection in the routes?

#[actix_web::main]
async fn main() -> Result<(), sqlx::Error> {
    let db_url = env::var("DATABASE.URL").expect("DATABASE.URL is not set in .env file");

    let mut listenfd = ListenFd::from_env();

    // Create a connection pool
    let db_pool = PgPoolOptions::new()
        .max_connections(5)
        .connect(&db_url)
        .await?;

    let mut server = HttpServer::new(move|| {
        App::new()
            .data(db_pool.clone()) // pass database pool to application so we can access it inside handlers
            .service(hello)

Also, am I supposed to clone the connection object here? Wouldn't I be just copying it? I thought it would be better to do just point to its existing value `.data(&db_pool), but the compiler says thats wrong.

4 replies
KOKOU AFIDEGNON
@afidegnum
from this example, request.match_info returns the path name and favico.ico, which triggers an error. what alternative do you suggest ?
async fn pages(request: HttpRequest) -> impl Responder {
    let name = request.match_info().get("name").unwrap_or("World");
    format!("Hello {}!", &name)
}
19 replies
KOKOU AFIDEGNON
@afidegnum
a quick one, should favicon.ico tied to a specific handler or i can discard it since there are multiple handlers which might require it ?
.service(web::resource("/favicon.ico").route(web::get().to(index)))
salfonseca
@salfonseca
Hi, I am trying to use HttpAuthentication::bearer in a project that also uses actix-cors, if I use HttpAuthentication::bearer or actix-cors alone it works fine, but if I use both I get an error saying that cors has block the request due to No 'Access-Control-Allow-Origin' header is present on the requested resource. I've even tried with Cors::permissive(). I don't know if these two crates are not compatible or is a bug in actix-web-httpauth, I will appreciate some guidance, do I have to submit a bug? my main code is: ```#[actix_rt::main]
pub async fn init() -> std::io::Result<()> {
let port = env::var("PORT").unwrap_or_else(|_e| "8000".to_string());
let mut socket = "127.0.0.1".to_string();
socket.push(':');
socket = socket + &port;
let db_state = db_mongodb::DB::init().await;

HttpServer::new(move || {
    App::new()
        .wrap(
            //Cors::default()
            Cors::permissive()
        )
        .wrap(IdentityService::new(
            CookieIdentityPolicy::new(&PRIVATE_KEY)
                .name("auth")
                .http_only(false)
                .path("/")
                .secure(false),
        ))
        .data(db_state.clone())
        .service(
            web::scope("/api")
            .wrap(HttpAuthentication::bearer(auth::validator))
            .configure(routes::init_secured)
        )
        .service(
            web::scope("/public")
            .configure(routes::init_public)
        )
})
.bind(socket).unwrap()
.run()```
11 replies
Darragh Van Tichelen
@Kruptein
Hi, I'm using HttpAuthentication bearer as an authentication middleware layer, I have difficulties trying to figure out how I can add/modify information that is passed to the eventual route handlers. i.e. in the validator function that I defined and need to pass to the HttpAuthentication::bearer, I would like to be able to set a specific String that is accessible in the route that gets called eventually.
matrixbot
@matrixbot
jplatte Hey. I'd like to wrap a specific route (method + path) in a middleware while not applying the middleware to the same path with different HTTP methods. Is that possible or do I need to check the HTTP method within the middleware?
matrixbot
@matrixbot
robjtede yeah this is actually possible with the macro syntax jplatte
matrixbot
@matrixbot
robjtede alternatively, i'm 99% you can use App::resource multiple times with non-overlapping methods and use the standard wrap fn there
matrixbot
@matrixbot
jplatte Not currently using macros, would prefer not to switch to that for this
jplatte multiple resources with the same path doesn't work, same as scope("") by the way (which kinda works, but not reliably, i.e. order matters and weird things like that)
matrixbot
@matrixbot
jplatte @robjtede if I were to switch to the macros, would every endpoint have list every single middleware used for it? (currently I have authn + authz wrapping almost everything and I'd really rather not repeat that over and over)
matrixbot
@matrixbot
robjtede That’s understandable. Not 100% sure what your best option is here.
jplatte Okay, thanks. Will create a new middleware that branches on the http method then if you can't recommend sth. better.
matrixbot
@matrixbot
robjtede It’s a shame the multiple resources thing doesn’t work. If you find a nice pattern for this I’d be interested to see
matrixbot
@matrixbot
jplatte I doubt there's a pattern to apply here. Seems to me like this requires more work inside actix-web, as in support for applying middlewares independently of routing.
jplatte Although if this does indeed work with the macros, it may not be that hard to get this to work? Have never looked into actix-web's routing logic, so not sure.
matrixbot
@matrixbot

jplatte * This is what I'm doing now:

pub async fn resource_mutation_admin_validator(
    req: ServiceRequest,
) -> actix_web::Result<ServiceRequest> {
    if req.method() == Method::GET {
        Ok(req)
    } else {
        admin_validator(req).await
    }
}

used as .wrap(Preprocess(authz::resource_mutation_admin_validator)) with that Preprocess middleware I was talking about upstreaming a bit ago

Abdelmonem Mostafa
@abdelmonem17

hello every one is it possible to create multiple apps in same server in actix-web version 3 like
HttpServer::new(move || {
vec![

 App::new()
     .service(resource("/test/{id}").route(get().to(test))),
App::new()
    .service(resource("/test1/{id}").route(get().to(test1)))

]
})
.bind("0.0.0.0:8000")?
.run().await;

21 replies
Abdelmonem Mostafa
@abdelmonem17
can anyone recommend good tutorial to master actix-web other than the websit because it is just give examples.
1 reply
matrixbot
@matrixbot
nitsuga5124 is there a way to achieve something similar to rocket's catch macro with actix? i want to return a custom page for specific status codes, rather than just a blank page
Kennymauro
@kennymauro_twitter

hey guys. I am new here. I am trying to use actix-web with cors. But I am getting an error like:

Compiling actix-cors v0.5.1
error[E0432]: unresolved import `tinyvec::tiny_vec`
  --> /home/caboquinho/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-cors-0.5.1/src/builder.rs:12:5
   |
12 | use tinyvec::tiny_vec;
   |     ^^^^^^^^^^^^^^^^^ no `tiny_vec` in the root

and also when I am declaring actix_cors:Cors I have the message extern location for actix_cors does not exist. I am using actix-cors = "0.5.1" on Cargo.toml. What do you think about it?

11 replies
Félix Lesc.
@EpiFouloux
Hello, I'm trying to use the httpmock crate with actix to mock some requests I make with actix-web::Client but it doesn't seem to work, the mock server is up but the request never reaches it. Are there any known compatibility issues between theses crates? I'm wondering if httpmock using isahc as a http framework is causing any issue
Félix Lesc.
@EpiFouloux
Also, is it really useful to use actix client instead of reqwest client directly?
Félix Lesc.
@EpiFouloux
        println!("test1");
        let client = Client::default();
        println!("test2");
        let request = client.get(MY_URI.as_str())
            .timeout(Duration::from_secs(5))
            .set_header("Authorization", token)
            .send();
        println!("test3");
        let mut resp = match request.await {
            Ok(val) => val,
            Err(error) => {
                log::warn!("{}", error);
                return Err(ServiceError::MyError);
            }
        };
        println!("test4");
Even with some timeout the test4 print is never reached, and my test is infinitely looping.
If MY_URI is invalid like "google.com" an error is returned, but if its a mock server running locally with mockito or httpmock or a valid one ("http://www.google.com") it loops
1 reply
Darragh Van Tichelen
@Kruptein
Hi, I would like to use actix-files to serve some static files, I would also like to have an authentication + cors middleware set for all other services, is there a way to apply a set of middleware on a group of services ?
10 replies
because right now the files also require auth as a result
Trystram Jean-Baptiste
@jbtrystram
Hi ! Is there a way to conditionally enable a service in App? Like the Condition middlware does (https://docs.rs/actix-web/1.0.8/actix_web/middleware/struct.Condition.html) but for an http service ?
Thanks for your help and thanks for working on this easy and well documented framework :)
10 replies
KOKOU AFIDEGNON
@afidegnum
won't it be nice for middleware::Logger to add colored output ?
Vinnie Caprarola
@vcapra1
Is there any way to conditionally start the actix system? Say, for example, I only want to start a server if the --server flag is provided to my program, otherwise I don't want to start a server. From what I've seen it just starts automatically when the program starts which isn't what I want
fakeshadow
@fakeshadow
Do not use proc macro and start it manually with your condition
8 replies
proc macro is for easy async
trevor arjeski
@trevarj
hi all, why can't i get app_data from a request inside a middleware? request.app_data() is always empty
41 replies
Greg Rauhöft
@g-rauhoeft
Hello everyone, I'm having trouble with creating a route that accepts multipart form data in addition to url parameters. The header of my handler looks like this:
async fn post_files(mut payload: Multipart, web::Path((proj, name, version)): web::Path<(String, String, String)>) -> Result<HttpResponse, Error>
payload.try_next() never returns Ok though. Does anyone have any idea how to debug this or see what I'm doing wrong? Thanks in advance!
2 replies
Michael van Niekerk
@mvniekerk
WebSocket question:
I want to have an http endpoint be set up as a WebSocket proxy to another server. As in all the text from the local connection gets sent to/from the other server (proxy).
Any suggestion or examples how?
5 replies
luopan
@loloxiaoz
does anybody use wasm in actix-web?
I want to write some web interfaces in wasm and some web interfaces in origin rust at the same time
is this possible?
1 reply
matrixbot
@matrixbot
jplatte Does anybody here have an idea why returning a URL in a redirect (HttpResponse::SeeOther().header(header::LOCATION, url).finish()) would result in the client redirecting, but getting an error when directly accessing the URL works?
jplatte This is a presigned GET URL for an S3-compatible storage, if that is useful info to anyone..