Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 17 19:13

    robjtede on master

    tweak migration document (compare)

  • Feb 17 08:12
    stanley355 commented #2650
  • Feb 17 01:07
    stanley355 commented #2650
  • Feb 16 14:10
    robjtede commented #2650
  • Feb 16 14:09
    robjtede labeled #2650
  • Feb 16 14:09
    robjtede closed #2650
  • Feb 16 14:09
    robjtede commented #2650
  • Feb 16 12:53
    stanley355 opened #2650
  • Feb 16 03:44

    github-actions[bot] on gh-pages

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

  • Feb 16 03:32

    github-actions[bot] on gh-pages

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

  • Feb 16 03:13

    robjtede on test-v0.1.0-beta.13

    (compare)

  • Feb 16 03:13

    robjtede on http-test-v3.0.0-beta.13

    (compare)

  • Feb 16 03:13

    robjtede on master

    prepare actix-http-test release… prepare actix-test release 0.1.… (compare)

  • Feb 16 03:13

    github-actions[bot] on gh-pages

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

  • Feb 16 03:11

    robjtede on actors-v4.0.0-beta.12

    (compare)

  • Feb 16 03:11

    robjtede on master

    prepare actix-web-actors releas… (compare)

  • Feb 16 03:10

    robjtede on awc-v3.0.0-beta.21

    (compare)

  • Feb 16 03:10

    robjtede on master

    prepare awc release 3.0.0-beta.… (compare)

  • Feb 16 03:07

    robjtede on http-v3.0.0-rc.3

    (compare)

  • Feb 16 03:07

    robjtede on master

    prepare actix-http release 3.0.… (compare)

Félix
@felix.maneville:qonfucius.team
[m]
Should every endpoint function be async ? Or is it not useful?
1 reply
Xu Desheng
@xudesheng
I'm looking for an example for this use case: 1) website assets have been ready: index.html (1k), index.js(315k), wasm.js(9k), xxx.wasm(300k). 2) I want all assets can be provided as gzip. 3) I want all assets can be automatically gzipped during compiling time and it's part of the final binary file. 4) with this kind of setting, actix-web doesn't need to zip the assets during runtime but still can provide gzipped format to the client. Do we have this kind of example? Thanks.
nicolaujr
@nicolaujr
Hi, I'm looking for a example to setup the X_FRAME_OPTIONS on my server
Could't find anything in the docs
anyone can give me some direction?
Do I need to create a custom middleware to inject the header in every response?
nicolaujr
@nicolaujr
Just found the DefaultHeaders middleware, if anyone is interested
Roshan Rajan
@roshanjrajan
Hi! I was wondering if it is possible to extract the path name to be used for logging purposes. I have many of these created but wanted to keep track of what requests are hit the most. Is there a way to get this information? I am looking to get the string "/api/endpoint1" in the example below.
#[get("/api/endpoint1")] 
async fn api_request() -> Result<String> {
    Ok(String::from("Hello World"))
}
Mehmet ERİBOL
@mehmeteribol_gitlab
Hi. I am using v4 beta 10. It was working couple of days ago but now i get error like this;
#[post("/login")]
async fn post_login(user: Data<LoginUser>) -> Result<HttpResponse, Error> {
    Ok(HttpResponse::Ok().json(1))
}
.service(web::resource("/login").route(web::post().to(post_login)))
   |                                                                -- ^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for `post_login`
   |                                                                |
   |                                                                required by a bound introduced by this call
CKalt
@CKalt
Anyone know how to capture type mismatch errors that result when using the Path information extractor so that I can produce a custom JSON format result instead of the default. For example I would like wrap the default error that gets emited like "Query deserialize error: invalid digit found in string" in a JSON object. But from the doc I'm not seeing how I might do this. I see a section on how to generate my own custom errors, but not how to capture and customize the default errors. Thank you for your help!!
2 replies
Ashanti Mutinta
@AshantiMutinta
Does anyone have an issue with tcp connections not being reused enough? Looks like there is a long standing issue in hyper and I'm trying to circumvent that
Ashanti Mutinta
@AshantiMutinta
Turned off keep alive and it seems to be working now
Ashanti Mutinta
@AshantiMutinta
Nvm looks like some concurrency limiting helps the most
asonix (he/they)
@asonix:matrix.asonix.dog
[m]
what are you using that depends on hyper? Actix Web and AWC don't
Ashanti Mutinta
@AshantiMutinta
My actix service is sending of multiple http requests using requests (one per api call) and im getting address not in use errors after I ramp up my performance testing.
Ashanti Mutinta
@AshantiMutinta
Using reqwest *
Kunjan Dalal
@kunjee17
What is middle ware scene in latest actix 4.0. I still need to use actix-services or something changed? Example of middle ware in actix examples repository is still ponited to actix 3. I just need to add some telemetry and authentication - authorization stuff.
2 replies
Aaron McLeod
@agmcleod
Hey there, im attempting to update a small application of mine to use the RC. However im getting build errors.
4 replies
Aaron McLeod
@agmcleod

Sorry have another question, just wondering if i can improve the code ergonomics a little. Prior to upgrading i'd have code like this:

let (game, rounds) = block(move || {
    let game = Game::find_by_id(&connection, game_id)?;
    let rounds = Round::belonging_to(&game).load::<Round>(&connection)?;
    Ok((game, rounds))
})
.await?;

Now with the changes to block(), it wraps the result for me. Since i want errors to return from the db operations there, i want to keep my own result. But this makes for a bit more code:

let data: Result<(Game, Vec<Round>), Error> = block(move || {
    let game = Game::find_by_id(&connection, game_id)?;
    let rounds = Round::belonging_to(&game).load::<Round>(&connection)?;
    Ok((game, rounds))
})
.await?;

let (game, rounds) = data?;
1 reply
Ruben De Smet
@rubdos:rubdos.be
[m]
    HttpServer::new(move || {
        let auth = HttpAuthentication::bearer(bearer_auth_validator);
        App::new()
            .app_data(state.clone())
            .wrap(middleware::Logger::default())
            .wrap(auth)
            .service(put_job)
            .service(next)
    })
I got an application like this. I would like to put the auth only with the two services, and add another service without the bearer authentication. How would I go about that?
Ruben De Smet
@rubdos:rubdos.be
[m]

Fiddled a bit with it, looks like

    HttpServer::new(move || {
        let auth = HttpAuthentication::bearer(bearer_auth_validator);
        App::new()
            .app_data(state.clone())
            .wrap(middleware::Logger::default())
            .service(metrics)
            .service(web::scope("").wrap(auth).service(next).service(put_job))
    })

works

Ratnadeep Bhattacharya
@ratnadeepb
I have been using actix-web for a while and currently attempting to build an example where each actor/app has a local copy of some data and communicates/syncs it with a global manager through async channels. I wonder if there is a good way of providing each actor with local storage/data structures?
Larry Dewey
@TheSilentDrifter_gitlab
Is there a location documenting the expected number of release candidates before a major release? Just wondering when the 4.0.0 will come out of rc.
ossgroupp
@ossgroupp
Hello everyone, not new to programming or web development, but brand new to rust and actix-web...just saying hey. I've been developing mostly in the java/typescript graphql/react/etc area for a little while now but looking into exploring what rust has to offer in terms of nextgen web development particularly with microservices
Kunjan Dalal
@kunjee17
Just came to know that Actix is finally V4. Thanks @robjtede and team for all the effort and helping early adopters like me to sort out issues :)
tglman
@tglman:matrix.org
[m]
🎉
Izdihar
@tengkuizdihar:matrix.org
[m]
Morning, does anyone have an example of actix + protobuf service? Most of the time I've only seen protobuf with enums and struct but no service. I would assume it would create a service trait or something.
Erlend Langseth
@Ploppz
                            .wrap(Condition::new(
                                keycloak_auth.is_some(),
                                keycloak_auth.clone().unwrap(),
                            ))
This doesn't work because if it's None it will panic... What can I do here?
Wouldn't it be an idea to impl Transform for Option<T>?
1 reply
Erlend Langseth
@Ploppz
made my own Either middleware
Samrose Ahmed
@Samrose-Ahmed
Hi, does anyone know how to write a simple middleware that runs after the response is returned to client. I want to do some custom async task (e.g. emit metric) that doesn't impact response based on some state set during request processing.
2 replies
robjtede
@robjtede:matrix.org
[m]
https://docs.rs/actix-web/latest/src/actix_web/middleware/logger.rs.html#332
is the Drop impl for the response body stream wrapper
basically when this gets Drop'd you know the stream has either completed or errored
important bit is just res.map_body(...) (line 321) which you can use to wrap the stream in your own struct with other bits you'll need when the stream is done
MGlolenstine
@mglolenstine:matrix.org
[m]

I was wondering what the best way of encrypting proxied data through websockets would be.
I'm essentially making a proxy, but I don't want to be able to see the data.
I was thinking about implementing a TLS-like handshake, but then the server still gets both certificates and the encryption is breakable.

I'm going to be sending passwords and usernames through the network and the only server-side processing I'm going to be doing is mapping WSS streams to a random id.

tglman
@tglman:matrix.org
[m]
Is there a way to access a session from a guard in 4.0 ? for example:
.guard(guard::fn_guard(|req| is_logged(req.get_session())))
1 reply
Gerald Nash
@aunyks
Hi! Does anyone have an example of accessing shared app state (added via data()) from middleware?
I imagine I have to access the request’s extensions but I’m not sure
Gerald Nash
@aunyks
Thanks! Looks like this is just what I need
Kesav Kolla
@kesavkolla

I need to setup a connection bb8 connection pool inside actor startup. The bb8 pool builder is async call whereas started fn in Actor is sync. How do I get this initialization done?
Here is my code:

#[derive(Debug, Default)]
pub struct RedisActor {
    pub pool: Option<Pool<RedisConnectionManager>>,
}

impl Actor for RedisActor {
    type Context = Context<Self>;

    fn started(&mut self, ctx: &mut Self::Context) {
        let manager = RedisConnectionManager::new("redis://localhost").unwrap();
        self.pool = Option::from(bb8::Pool::builder()
                .max_size(5)
                .build(manager).await.unwrap());
    }
}

The line await is failing because I can't use await inside normal function. Can someone help how to do this kind of pool initialization inside the actor start

hanbo1990
@hanbo1990
Hi here, I am new to actix-web and would like to get some help from you. Is it possible to make actix as a proxy and add middleware to modify the request/response body?
tglman
@tglman:matrix.org
[m]
is possible to use actix-web as a proxy, and change the request response, there is an example about it, even though without middleware
hanbo1990
@hanbo1990
cool, that helps a lot, thank you
Erlend Langseth
@Ploppz

Having two problems with migration to v4.

        fn render_404() -> HttpResponse {
            let body = serde_json::to_string(&ErrorResponse {
                code: 404,
                message: "Endpoint not found".into(),
            })
            .unwrap();
            HttpResponse::with_body(StatusCode::NOT_FOUND, BoxBody::new(body))
        }
        App::new()
            // ....
            .default_service(web::route().to(render_404))

I get error:

the trait Handler<_> is not implemented for fn() -> actix_web::HttpResponse {render_404}

Secondly, I get this error on my own middleware:

error[E0271]: type mismatch resolving `<KeycloakAuth<[closure@src/main.rs:162:33: 165:14]> as Transform<actix_web::scope::ScopeService, ServiceRequest>>::Response == ServiceResponse`
   --> src/main.rs:206:35
    |
206 | ...                   .wrap(either_middleware::OneOrAnother::new(keycloak_auth.clone()))
    |                        ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `EitherBody`, found struct `BoxBody`
    |                        |
    |                        required by a bound introduced by this call
    |
    = note: expected struct `ServiceResponse<EitherBody<_>>`
               found struct `ServiceResponse<BoxBody>`
note: required because of the requirements on the impl of `Transform<actix_web::scope::ScopeService, ServiceRequest>` for `OneOrAnother<KeycloakAuth<[closure@src/main.rs:162:33: 165:14]>, KeycloakError>`
   --> src/either_middleware.rs:22:22
    |
22  | impl<S, Req, T1, T2> Transform<S, Req> for OneOrAnother<T1, T2>
    |                      ^^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^^^^^

The whole middleware is here: https://bpa.st/HXXQ
Wondering what has changed that made these two things now not work

1 reply
Erlend Langseth
@Ploppz
Forgot to mention: I actually am coming from the beta.19
Erlend Langseth
@Ploppz
I solved the first error (it just needed to be an async fn). Now I just have the middleware problem. I find it difficult to solve because there is neither EitherBody or BoxBody explicitly in my code, not sure where that requirement comes from.