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)

aceArt.de
@aceart.de:matrix.org
[m]
not very Rusty :|
robjtede
@robjtede:matrix.org
[m]
Type maps are quite commonly used even in Rust
Varun Kamra
@varunkamra
Hey guys I am new to actix web, I wanted to configure swagger and load the swagger ui on the server
2 replies
how do I do that?
I can't find any examples online
PeterPierinakos
@PeterPierinakos
Does actix's examples repo provide any example which implements a file upload API endpoint via form-data and a request payload? I can't find any and I'm not sure how to do this. Should I use the actix-multipart crate to achieve this?
Radu
@raduc4:matrix.org
[m]
Hi, can I ask questions here?
1 reply
Kunjan Dalal
@kunjee17
Hi, I am little stuck. I am using jsonrpc-v2 library but I can't implement session or identity to secure rpc end point. I try to understand the code but couldn't get my head around. It would be great if someone can help me. I have file issue on repo kardeiz/jsonrpc-v2#22 . Do let me know if any further info is required .
vibhuh
@vibhuh
has overflowed its stack
vandenoever
@vandenoever:kde.org
[m]
Is there a way to make an actix_web::App handle a TcpStream directly? (or another instance of AsyncRead + AsyncWrite + Unpin)
vandenoever
@vandenoever:kde.org
[m]
e.g. pass an incoming TcpStream to an app somehow like is possible with hyper::server::Http::serve_connection
Quirin Hügler
@Quronox

Hey, I have a question that might be easier asked than figured out:

There is the implementation of a Responder that performs Database Operations:

#[delete("/logout")]
async fn logout(authenticated_user: AuthenticatedUser, db: web::Data<Database>) -> impl Responder {
    db.collection::<session::Schema>(session::COLLECTION).delete_one(doc!{ "user_id": authenticated_user._id }, None).await.unwrap();
    return HttpResponse::Ok().finish();
}

What I want to do is to minimize use of unwrap() in favor of proper error handling by calling the database operation with question mark and return status 500 if the database operation fails. This assumes to change the definition like:

#[delete("/logout")]
async fn logout(authenticated_user: AuthenticatedUser, db: web::Data<Database>) -> actix_web::Result<impl Responder> {
    db.collection::<session::Schema>(session::COLLECTION).delete_one(doc!{ "user_id": authenticated_user._id }, None).await?;
    return HttpResponse::Ok().finish();
}

The db.collection() call returns a Result<Option<session::Schema>, mongodb::error::Error>,
and the problem then is: "the trait ResponseError is not implemented for mongodb::error::Error",
trying to implement the trait results in: "only traits defined in the current crate can be implemented for arbitrary types"
is there any clean way to make actix deal with mongodb::error::Error or even with other errors like bcrypt::BcryptError for instance when hashing passwords?

Côme
@come_744:tedomum.net
[m]
You can define your own generic error type and implement Into<MyError> for all types of error you manage. The status could be set during conversion. (Maybe it is not the solution you are looking for)
Quirin Hügler
@Quronox

Well, for People eventually searching for this - the solution is:

#[delete("/logout")]
async fn logout(authenticated_user: AuthenticatedUser, db: web::Data<Database>) -> Result<HttpResponse, Box<dyn Error>> {
    db.collection::<session::Schema>(session::COLLECTION).delete_one(doc!{ "user_id": authenticated_user._id }, None).await?;
    return Ok(HttpResponse::Ok().finish());
}

This will deal with any error that may occurs, for the price of not being able to differentiate between different Errors (Does it return 500 due to a Database problem or is it a bcrypt encryption error?)

For any tuned error handling, one has to implement custom error types, just like @come_744:tedomum.net suggested

Satvik Pendem
@satvikpendem
Is a WebSocket library like tokio-tungstenite usable with actix-web? Because it seems to be the only thing that still requires #[actix_web::main] rather than #[tokio::main], and I need WebSocket support so I was thinking I could use #[tokio::main] and tokio related libraries like tokio-tungstenite, so just wondering if this is doable or not with actix-web.
Kunjan Dalal
@kunjee17
@robjtede:matrix.org As far as I know actix (actor system) is decoupled from actix-web. Now if I want to use it with Actix-web then there are any examples ? I want to use actors for more of business / logical purpose for current requirements. So, I thought it would be better to use actix actor system with actix-web instead of something like tiny-tokio-actors or riker or similar stuff. I did check web socket example but it using actix-web-actors wrapper to provide ws support. I want more of actor system that can happily combined with actix-web.
robjtede
@robjtede:matrix.org
[m]
I’d suggest googling “actors with tokio” to find Alice Rhyl’s blog post about it if you want to use actor-ish business logic within Actix Web. actix is in maintenance mode.
Luis Roel
@luisroel91
Hello!
I am wondering whether I could achieve the same using actix-web::rt?
Kunjan Dalal
@kunjee17
Thanks @robjtede:matrix.org . I did read that one. Tokio tiny actor is actually based on that blog only. Thanks for tip. ☺️
Kunjan Dalal
@kunjee17
If use tokio based actor then i need to switch from actix web main to tokio main or it will work with actix web main as well? @robjtede:matrix.org
2 replies
Tanner Wilcox
@twiclo

https://docs.rs/actix-web-httpauth/latest/actix_web_httpauth/middleware/struct.HttpAuthentication.html#method.bearer

Can someone explain to me the reasoning behind the error returning a (Error, ServiceRequest) on this function?

2 replies
Kunjan Dalal
@kunjee17
@twiclo I might be wrong but it is mostly for logging purpose on client side. Error + what request created that error.
volsa
@volsa
Is there a way to only log certain endpoints, e.g. I want to only log endpoints starting with /v1/.* to reduce the overall logging clutter
I know there's exclude_regex (https://actix.rs/actix-web/actix_web/middleware/struct.Logger.html#method.exclude_regex) but AFAIK negative look-ahead (which would solve my issue) isn't supported by the regex crate
Am I missing something?
robjtede
@robjtede:matrix.org
[m]
you can wrap the logger only on those scopes/resources
volsa
@volsa
How would I do that? Currently the code looks like this:
    HttpServer::new(move || {
        App::new()
            .app_data(state.clone())
            .service(signatures_by_text)
            .service(signatures_by_hash)
            .wrap(Cors::permissive())
            .wrap(Logger::new("(%Ts) %a: %r"))
    })
    .bind_openssl(/* ... */)?
    .run()
    .await
robjtede
@robjtede:matrix.org
[m]
do you have a Scope for the /v1/ endpoints ?
volsa
@volsa
No I didn't, but taking a closer look at the scope documentation I fixed my issue
Thanks for pointing me towards scopes :)
Richard Jansen
@rj76
Hello, I have an multi-tenant application that uses the hostname to determine the tenant. Does TestRequest:: with_uri() also accept a full hostname? Or is there another way to set this?
Wangrui Lei
@Emelialei88

Hi! In order to support HTTPS, I added

actix-web = { version = "4.0.0", features = ["openssl"] }
openssl = { version = "0.10", features = ["v110"] }

to Cargo.toml but got the error message below. Could anyone help?

image.png
Proem Meas
@measproem
Hi All,
I struggled how to call async/await function in Middleware, I have stored user session_id in database need to verify every incoming request to do that I called to database with async function any sample repo I can follow?
Proem Meas
@measproem
I solved my above problem may be help someone who the same problem can check middleware at https://github.com/actix/actix-extras with actix-web-httpauth it supports async we can continue code make support JWT or call to database execute query base on await
James Gill
@JamesPatrickGill
Hi I am looking to make requests from my actix 4 handlers, I have done a bit of googling and wondering if my idea of just using reqwest to do this makes sense or is there anything obvious I'm missing in the docs
2 replies
Richard Jansen
@rj76
So I'm still looking for a way to change the host in the requests while testing, I found the place to change this is in AppConfig but that's private. There's also a method set_host but that's also private. Is there no way to change the host to something else than localhost:8080?
3 replies
Cody64
@Cody64
This message was deleted
2 replies
jsplate
@jsplate
Hi there,
I am trying to send a JSON object via websocket which contains a Vec (raw image bytes) and some other fields.
I was using JS and socket.io before where this was marshalled automatically.
What is the best solution for sending this? WebsocketContext only provides text and binary. Do I have to send everything binary and create my own binary data format?
asonix (he/they)
@asonix:matrix.asonix.dog
[m]
if you want to include it in the json, you could base64 encode the bytes. otherwise, websockets forbid reordering message frames so you could send a "next frame will be image bytes" message, then the bytes
johrpan
@johrpan:johrpan.de
[m]
Hello everyone! What would you recommend as a idiomatic way to handle an independent set of paths using a single handler? I have a dynamically generated vector of paths that I want to handle using a specific function. Options I'm considering include constructing a route object for each path and generating a regex that matches all the paths. But I wonder whether there is some official way of doing this. What do you think?
2 replies
johrpan
@johrpan:johrpan.de
[m]
robjtede: Thanks, I think that's what I will do.
Tanner Wilcox
@twiclo1_gitlab
pub struct Context {
  pool: sqlx::PgPool,
  user: AuthedUser,
  maps: GoogleMapsClient
}
impl Context {
  pub async fn new(req: &actix_web::HttpRequest, claim: &Claim) -> Result<Self, Error> {
  dbg!(&req.app_data::<GoogleMapsClient>());
    Ok(Context {
      pool: ...
      user: AuthedUser { ... },
      maps: req.app_data::<GoogleMapsClient>().unwrap().clone()
    })
  }
}



let maps = GoogleMapsClient::new(&std::env::var("GOOGLE_API_KEY").expect("GOOGLE_API_KEY must be set"));

HttpServer::new(move || {
  let app = App::new();
  app
    .app_data(Data::new(maps.clone()))
  }).bind(...).run().await
The dbg on line 8 is logging out None. Am I losing my data because I'm cloning it?
11 replies
Andrew Low
@kahkhang

Hi, I am unable to compile actix-web 4.2.1. It gives me an error

   Compiling actix-web v4.2.1
error[E0107]: missing generics for trait `AsRef`
   --> /Users/andrew.low/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-4.2.1/src/types/path.rs:56:66
    |
56  | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, AsRef, Display, From)]
    |                                                                  ^^^^^ expected 1 generic argument
    |
note: trait defined here, with 1 generic parameter: `T`
   --> /Users/andrew.low/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/convert/mod.rs:158:11
    |
158 | pub trait AsRef<T: ?Sized> {
    |           ^^^^^ -
    = note: this error originates in the derive macro `AsRef` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add missing generic argument
    |
56  | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, AsRef<T>, Display, From)]

Can I know what I'm doing wrong? Thank you! These are my dependencies

[dependencies]
rand = "0.7.3"
rand_distr = "0.2.2"
assert_approx_eq = "1.1.0"
chrono = "0.4"
itertools = "0.9.0"
libmath = "0.2.1"
dotenv = "0.9.0"
actix-web = "4"
serde = "1.0.106"
log = "0.4.11"
futures = { version = "0.3.5", default-features = false }
rayon = "1.3.1"
log4rs = "1.1.1"
3 replies
József Fényes
@pingvin12
image.png
Hey, im trying to log on request from a function, there is no output even when setting RUST_LOG to 1, and somehow from this part I cant even set a break point. What am I doing wrong?
rootBiao
@rootBiao
how can I use http2 without using https?
3 replies
rootBiao
@rootBiao
can I use http1 and http2 Simultaneously, making the server listens on same address.I find a way to use http1 and http2 Simultaneously but needing the server listens on different address.