Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 18 22:37

    github-actions[bot] on gh-pages

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

  • Apr 18 22:35
    robjtede synchronize #2168
  • Apr 18 22:34

    robjtede on master

    Named file service (#2135) (compare)

  • Apr 18 22:34
    robjtede closed #2135
  • Apr 18 22:34
    robjtede closed #2115
  • Apr 18 03:46
    ibraheemdev synchronize #2135
  • Apr 18 02:56
    svenstaro commented #2135
  • Apr 18 02:12
    andy128k ready_for_review #2168
  • Apr 18 02:12
    andy128k edited #2168
  • Apr 18 01:01
    andy128k synchronize #2168
  • Apr 18 00:56
    andy128k opened #2168
  • Apr 17 18:17

    fakeshadow on actix_http_service

    (compare)

  • Apr 17 18:16

    fakeshadow on actix_http_client_wss

    (compare)

  • Apr 17 17:36

    fakeshadow on actix_http_client_wss

    Fix client wss protocol (compare)

  • Apr 17 14:56

    github-actions[bot] on gh-pages

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

  • Apr 17 14:55

    robjtede on test-v0.1.0-beta.2

    (compare)

  • Apr 17 14:54

    robjtede on master

    prepare actix-test release 0.1.… (compare)

  • Apr 17 14:43
    robjtede closed #2055
  • Apr 17 14:42
    robjtede unpinned #2166
  • Apr 17 14:39

    robjtede on web-v4.0.0-beta.6

    (compare)

dotyoric
@dotyoric:matrix.org
[m]
Code has been in production for a few months, too.
(or "transpile", if you prefer :) )
1 reply
dotyoric
@dotyoric:matrix.org
[m]
On a different note, my code just broke, possibly related to the release of actix-utils 3.0.0-beta.3.
   Compiling actix-http v3.0.0-beta.4
error[E0432]: unresolved import `actix_utils::timeout`
  --> /home/yoric/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-http-3.0.0-beta.4/src/client/connector.rs:17:18
   |
17 | use actix_utils::timeout::{TimeoutError, TimeoutService};
   |                  ^^^^^^^ could not find `timeout` in `actix_utils`
(etc.)
I'm aware it's one of the risks of using beta versions, but I wonder if there's a solution at hand.
I ran a cargo clean && cargo update today, it built before that, not sure when the issue showed up, but my CI only broke one hour ago, so I assume it's very recent.
(which seems to be confirmed by the fact that actix-utils lost timeout only today)
Rob Ede
@robjtede
you can pin versions that break stuff
eg: actix-utils = "=3.0.0-beta.2"
apologies for this, i'm working to release a bunch of new betas currently
dotyoric
@dotyoric:matrix.org
[m]
No problem and thanks for the great work on actix-* :)
If you tell me I just need to take a break, I can do that, too :)
It's lunchtime anyway.
fakeshadow
@fakeshadow
try not to run cargo update with actix-web betas
You want to stay on a combination works if possible. any update could break your project.
dotyoric
@dotyoric:matrix.org
[m]
Yeah, I did that to try and understand why my CI broke down.
I suppose I should take the habit of pushing Cargo.lock to my git repo.
dotyoric
@dotyoric:matrix.org
[m]
In that specific case, the following seems to work around the issue:
$ cargo update -p actix-utils --precise 3.0.0-beta.2
dotyoric
@dotyoric:matrix.org
[m]
I have a general design question, possibly OT.
When there's some kind of panic! in a request, actix-web handles it gracefully, failing the request but keeping the server alive.
Now, my server also has a number of background tasks, e.g. it checks every few minutes for updates from another server.
What's the best design to handle panic! in such background task gracefully, without killing the server or the internal background task loop?
Right now, I have a loop that looks like
loop {
   if let Err(err) = tokio::task::spawn(...).await {
      warn!("Error in background task {:?}", err);
   }
   tokio::time::sleep(...).await;
}
Is this a good design? Would actix agents somehow help me make it better/nicer?
Rob Ede
@robjtede
new set of betas for everything (including cors, redis etc) released:
https://github.com/actix/actix-web/releases
https://github.com/actix/actix-extras/releases
Wouter de Bie
@wouterdebie
Hi all! I'm fairly new to Rust and to actix-web, and I'm struggling with some sync/async stuff.. I'm trying to implement Stream, where in the stream I make some external HTTP requests. How do I call an async function (and wait for a result) in poll_next()?
9 replies
Henning Dieterichs
@hediet
Hi! Could it be that NamedFile from actix-files does not work together with Cors from actix-cors? It does not send me a CORs header, but my json endpoint does have CORs headers. Is this a bug?
7 replies
Sergiu Popescu
@sergiupopescu199

Hi, I have a question which I could find an answer.
I want to create a route #[post("/get_something/{limit}/{skip}")]
I would make that limit and skip are optional so if you request /get_something it uses some predefined values from limit and skip but if I give values for limit or skip or both it will take those values

which is the best way of doing it, using a Json<> or Path()? or I must create 3 routes?
Thanks in advance for help

Voodlaz
@Voodlaz

Why does tokio block actix? When I use tokio I can't connect to the server via websockets. the tokio code is time_now() function

actix code:

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    time_now();
    let port = env::var("PORT")
        .unwrap_or_else(|_| "8081".to_string())
        .parse()
        .expect("PORT must be a number");
    println!("Server is working on {:?}", port);
    let chat_server = Lobby::default().start(); //create and spin up a lobby
    HttpServer::new(
        move || App::new()
            .service(start_connection_route)
            .data(chat_server.clone())
    )
        .bind(("0.0.0.0", port))
        .expect("Can not bind to port")
        .run()
        .await
}

tokio code:

pub async fn time_now() {

    let mut time: currentTime = currentTime {
        dayTime: "".to_string(),
        seconds: 0,
        minutes: 0,
        hours: 0,
        days: 0,
        shift: 0,
    };

    let mut one_second = Duration::from_secs(1);
    actix::spawn(async move {
    loop {
        std::thread::sleep(one_second);
        time.seconds += 1;
        if (time.seconds == 60) {time.minutes += 1; time.seconds = 0}
        if (time.minutes == 60) {time.hours += 1; time.minutes = 0}
        }
    });
}
1 reply
rkfox
@rkfox
Hey there I have an async function that is a loop running alongside my http server in an#[actix_web::main]. the problem is that this spawns multiple of these async loops instead of just one. I have a feeling that the actix run time creates multiple threads running the same main function? I'm wondering how I can get this to run as a single instance.
9 replies
Alex Bluefall
@alexbluefall:matrix.org
[m]
I think you need to use Tokio's time::delay_for function instead of thread::sleep
vidyli
@vidyli
hi, I like to return a httpserver instance from a function, I did something like this,
2 replies
pub  fn start() ->HttpServer{
    HttpServer::new(move || {
        App::new()
            .data(state)
            .wrap(Logger::default())
            .wrap(cors)
            .configure(routes)
        })
        .bind(&bind_address)
        .unwrap_or_else(|_| panic!("Could not bind server to address {}", &bind_address))
}
however it doen't work
I got
pub fn start() -> HttpServer {
   |                   ^^^^^^^^^^ expected 4 type arguments
christian
@christian:matrix.boseck.net
[m]
Hello web-dev friends, I need to clean up my AppState after the webserver has stopped. Is there a proper way to do that?
sabine
@sabine

trying actix-web 4.0.0-beta.5, I'm adding a sqlx db pool as app data like this:

            .app_data(db_pool.clone())

In an implementation of actix_web::FromRequest, I try to get the data back vialet pool = req.app_data::<actix_web::web::Data<sqlx::PgPool>>().unwrap().clone(); However, I see a None value being returned by app_data here. What am I doing wrong?

3 replies
rkfox
@rkfox
Is there a good way to get actix HttpServer running in a different thread?
41 replies
help: the traitstd::marker::Sendis not implemented for(dyn std::any::Any + 'static)note: future is notSendas this value is used across an await
christian
@christian:matrix.boseck.net
[m]
Has someone any experience running actix_web as a windows service?
CallumDowling
@CallumDowling
Hi, I am trying to log IP addresses using %{r}a,
...
App::new()
.wrap(Logger::new(r#"real:%{r}a peer:%a "%r" %s %b "%{Referer}i" "%{User-Agent}i" %T"#)) 
...
It seems to not pick up the pattern and prints %{r}a
In logs
Using actix-web 3.3.2
rkfox
@rkfox
I'm trying to convert my actix-web project from v3 to v4, but I'm getting this error:
error[E0432]: unresolved import `actix_service::pipeline_factory` --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-http-3.0.0-beta.5/src/service.rs:13:21 | 13 | use actix_service::{pipeline_factory, IntoServiceFactory, Service, ServiceFactory}; | ^^^^^^^^^^^^^^^^ no `pipeline_factory` in the root
7 replies
Rob Ede
@robjtede
just an FYI if you're using any crates from the actix-extras repo hold off on upgrading actix-web until tomorrow
gondolyr
@gondolyr:matrix.org
[m]

Did actix-web beta-6 change how JSON bodies are parsed? The last version I was using was beta-5. I'm getting this error without changing anything except updating actix-web:

the trait bound `fn(actix_web::web::Json<routes::api::search::SearchParameters>) -> impl std::future::Future {<routes::api::search::search_repositories as actix_web::dev::HttpServiceFactory>::register::search_repositories}: actix_web::dev::Handler<_, _>` is not satisfied

My function looks like this:

#[post("/search_repositories")]
pub async fn search_repositories(
    query: web::Json<SearchParameters>,
) -> Result<HttpResponse, HttpResponse> {
    // ...
}
rkfox
@rkfox
I'm trying to to compile with actix-web v4. Getting this error:
30 replies
error[E0053]: method `error_response` has an incompatible type for trait
  --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-cors-0.6.0-beta.1/src/error.rs:53:5
   |
53 |     fn error_response(&self) -> HttpResponse {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `BaseHttpResponse`, found struct `actix_web::HttpResponse`
   |
   = note: expected fn pointer `fn(&CorsError) -> BaseHttpResponse<actix_web::dev::Body>`
              found fn pointer `fn(&CorsError) -> actix_web::HttpResponse
rkfox
@rkfox
I'm trying to create a middlware using the example from the actix website. Getting about 20 errors using the example code.
error[E0437]: type `Request` is not a member of trait `Transform`
  --> src/sessions.rs:24:5
   |
24 |     type Request = ServiceRequest;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Transform`

error[E0437]: type `Request` is not a member of trait `Service`
  --> src/sessions.rs:46:5
   |
46 |     type Request = ServiceRequest;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Service`
15 replies