Git Product home page Git Product logo

examples's Introduction

Actix Examples

Curated examples using the Actix ecosystem.

build status Chat on Discord

Community Showcase

  • Merino: Web service for Firefox Suggest.
  • Contile: The back-end server for the Mozilla Tile Service (MTS).
  • lemmy: A federated alternative to reddit in Rust.
  • MeiliSearch: Fast, Relevant and Typo-Tolerant Search Engine. Open source alternative to Algolia.
  • Martin: Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server.
  • hyperswitch: An Open Source Financial Switch to make payment open, fast, secure and reliable.
  • tokei.rs: The tokei.rs server code.
  • Labrinth: Rust-based backend to serve the modrinth API.
  • Barricade: Quickly add user registration and logon to any application.
  • Bloom: The simplest way to de-Google your life and business: Inbox, Calendar, Files, Contacts & much more.
  • GitArena: Software development platform with built-in VCS, issue tracking and code review.
  • Four in a Row - Server: An online version of the popular game four in a row, written in Rust on the server side and Flutter + Dart on the client.
  • Nitro Repo: An open source artifact manager. Rust back-end and Vue front-end.
  • mCaptcha: Proof of work based, privacy focused, libre CAPTCHA system. Crates used: actix-web, sqlx, redis, and lettre.
  • Zero2prod: Source code of zero to production series zero2prod.com. Paid book but some of the chapters is available online for free. The book compares and explains the chosen technologies, like Actix Web and SQLx.
  • Triox: A free file hosting server that focuses on speed, reliability and security.
  • binserve: A fast, secure, and easy to set up static web server written on top of Actix Web with routing, templating, and various other features.
  • Roseline: A personal web site and discord & IRC bot to access simple SQLite database. Demonstrates usage of various Actix and Actix Web concepts.
  • Dalted: Simple webapp that showcases the integration of image-rs with Actix Web for color blindness simulations.
  • Atomic-Server: Graph database with a dynamic schema, authorization and full text search.
  • Operator: A web server for static and dynamic content.
  • RCOS Telescope: The RCOS website and Discord bot.
  • WebThings Registration Server: Exposes an HTTP API that lets you register a WebThings Gateway for tunneling support
  • pict-rs: An image host API service
  • rustypaste: A minimal file upload/pastebin service
  • rustus: A TUS protocol implementation that helps you handle file uploads
  • gcs-proxy: A Google Cloud Storage download proxy
  • Actix-Web Shuttle Template: A somewhat opinionated template for getting started with an Actix Web API and hosting it on Shuttle.

Community Articles, Example Apps, Starters & Boilerplate Projects

Paid Resources

Contribute

Pull requests welcome for small, focused example projects demonstrating patterns or techniques.

Submissions also accepted to have your app or repo considered for the showcase lists.

examples's People

Contributors

apatrushev avatar arve0 avatar barafael avatar cgubbin avatar cheolgyu avatar danitrod avatar dependabot[bot] avatar digeratus avatar doumanash avatar dowwie avatar fafhrd91 avatar fairingrey avatar fakeshadow avatar jannic avatar johntitor avatar kellytk avatar leizzer avatar liuliuod avatar lukemathwalker avatar mohanson avatar mygnu avatar nyurik avatar pfrenssen avatar pka avatar robjtede avatar rofrol avatar sadika9 avatar svenstaro avatar vmalloc avatar zzau13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

examples's Issues

Is it possible to share app state between actors?

Is it possible to obtain db_addr inside QueueActor from app_state? For example, I want to store message from the queue to the DB, therefore I have to get DB connection inside QueueActor somehow. At the same time there should be simple REST API to GET data from the DB. Is it valid case in scope of actix, actix-web?

pub struct AppState {
    pub db_addr: Arc<Addr<DbActor>>,
    pub queue_addr: Arc<Addr<QueueActor>>
}
let server = server::new(|| {
     let db_addr = Arc::new(DbActor::start(host));
     let queue_addr = Arc::new(QueueActor::start(host));
     let app_state = AppState{db_addr, queue_addr};
     App::with_state(app_state)
            ...                              
});

'websocket' example appears to be out of date for client.rs

I might be missing something but the client.rs doesn't appear to up to date with the latest APIs. If I uncomment the client binary in the Cargo.toml, I see the following errors:

cargo build
   Compiling websocket v0.1.0 (/Users/mike/code/examples/websocket)
error[E0432]: unresolved imports `actix_web::client::ClientWriter`, `actix_web::client::Message`, `actix_web::client::ProtocolError`
 --> websocket/src/client.rs:6:33
  |
6 | use actix_web::client::{Client, ClientWriter, Message, ProtocolError};
  |                                 ^^^^^^^^^^^^  ^^^^^^^  ^^^^^^^^^^^^^ no `ProtocolError` in `client`
  |                                 |             |
  |                                 |             no `Message` in `client`
  |                                 no `ClientWriter` in `client`
  |                                 help: a similar name exists in the module: `ClientBuilder`

warning: unused import: `Message`
 --> websocket/src/client.rs:6:47
  |
6 | use actix_web::client::{Client, ClientWriter, Message, ProtocolError};
  |                                               ^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error[E0191]: the value of the associated type `Result` (from the trait `_impl_act_clientcommand::actix::Message`) must be specified
  --> websocket/src/client.rs:87:20
   |
87 | impl StreamHandler<Message, ProtocolError> for ChatClient {
   |                    ^^^^^^^ associated type `Result` must be specified

error[E0191]: the value of the associated type `Result` (from the trait `_impl_act_clientcommand::actix::Message`) must be specified
  --> websocket/src/client.rs:88:31
   |
88 |     fn handle(&mut self, msg: Message, ctx: &mut Context<Self>) {
   |                               ^^^^^^^ associated type `Result` must be specified

error: aborting due to 3 previous errors

Some errors occurred: E0191, E0432.
For more information about an error, try `rustc --explain E0191`.
error: Could not compile `websocket`.

Potential security Issue with the simple-auth-server

Hi everyone,

I had a question about the following piece of code in the handlers of the simple-auth-server:

impl Handler<AuthData> for DbExecutor {
    type Result = Result<SlimUser, ServiceError>;
    fn handle(&mut self, msg: AuthData, _: &mut Self::Context) -> Self::Result {
        use schema::users::dsl::{users, email};
        let conn: &PgConnection = &self.0.get().unwrap();

        let mut items = users
            .filter(email.eq(&msg.email))
            .load::<User>(conn)?;

        if let Some(user) = items.pop() {
            match verify(&msg.password, &user.password) {
                Ok(matching) => if matching {
                        return Ok(user.into());
                },
                Err(_) => (),
            }
        }
        Err(ServiceError::BadRequest("Username and Password don't match".into()))
    }
}

My question is that when the database is filtering out the user names it will immediately return, but if it finds it and tries to verify with an incorrect password it will only return after a lengthy amount of time. Is this not prone to a timing attack? This can leak information about which users exist in the database and which don't by a malicious attacker.

Thanks

Juniper implement Cors not working

Hello guys,
I used the example on the juniper folder, then added the cors. but the cors did not work.
Here's the extra I did:

    server::new(move || {
        App::with_state(AppState {
            executor: addr.clone(),
        })
            .middleware(middleware::Logger::default())
            .configure(|app| {
                Cors::for_app(app)
                    .allowed_origin("127.0.0.1:8000")
                    .allowed_methods(vec!["GET", "POST"])
                    .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
                    .allowed_header(header::CONTENT_TYPE)
                    .max_age(3600)
                    .resource("/graphql", |r| r.method(http::Method::POST).with(graphql))
                    .register()
            })
    }).bind("127.0.0.1:8000")
        .unwrap()
        .shutdown_timeout(2)
        .start();


if allowed_origin I replace with * it still does not work

log error :

 WARN 2018-12-07T08:53:57Z: actix_web::pipeline: Error occurred during request handling: Origin is not allowed to make this request

tls example not working in HTTP2

The tls example does not work in HTTP2 protocol. It fails during the handshake phrase.

cURL returns curl: (56) SSL_write() returned SYSCALL, errno = 32 or curl: (16) SSL_write() returned SYSCALL, errno = 41 or errno = 104 randomly.

Steps to reproduce:

$ cargo update
$ cargo run --locked
$ curl -ik --http2 https://localhost:8443/index.html
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

Some tracing log during my debugging (different setup than the example)

T0628 16:54:44.867886 393276 <unknown>:1078] Handshake::poll(); state=Handshaking::Flushing(_);
T0628 16:54:44.868024 393276 <unknown>:169] flush
T0628 16:54:44.868122 393276 <unknown>:180]   -> not a queued data frame
T0628 16:54:44.868287 393276 <unknown>:209] flushing buffer
T0628 16:54:44.868387 393277 <unknown>:371] event Readable | Writable Token(0)
T0628 16:54:44.868438 393276 <unknown>:1091] Handshake::poll(); flush.poll()=Ready
T0628 16:54:44.868565 393276 <unknown>:269] Error handling connection: connection closed unexpectedly

HTTP/1.1 works though:

$ curl -ik --http1.1 https://localhost:8443/index.html
HTTP/1.1 200 OK
content-length: 8
content-type: text/plain
date: Fri, 29 Jun 2018 01:08:05 GMT

Welcome!

simple-auth-server don't compile

Trying to compile simple-auth-server lead to this error :

error[E0277]: the trait bound `uuid::Uuid: diesel::Expression` is not satisfied
  --> simple-auth-server/src/models.rs:39:52
   |
39 | #[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
   |                                                    ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `uuid::Uuid`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert uuid::Uuid`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Uuid>` for `&'insert uuid::Uuid`

It is a bad idea to use .handler("/", ...)

Everything that is written below is my opinion, not an instruction.

I think this is a bad idea. You can see similar code here (static_index) and here (simple-auth-server).

This is bad because you use it to access the "/static" folder or to open the index.html file automatically.
And if in the browser you open "/abc", then you will get the file "/abc/index.html" because you are not using the ".index_file()" method correctly

Bad idea:

.handler(
    "/",
    fs::StaticFiles::new("./static/").unwrap().index_file("index.html"))

Also, you can't use code like this:

.handler(
    "/",
    fs::StaticFiles::new("./static/").unwrap().index_file("index.html"))
.resource("/", |r| r.f(index))

You should use ".handler" only for specific folders. For ex.:

.handler(
    "/css",
    fs::StaticFiles::new("./static/css/").unwrap())
.handler(
    "/imgs",
    fs::StaticFiles::new("./imgs/").unwrap())
.handler(
    "/download",
    fs::StaticFiles::new("./download/").unwrap())
.handler(
    "/js",
    fs::StaticFiles::new("./static/js/").unwrap())
.resource("/", |r| r.f(index))

And if you want the "index.html" file to open automatically on the main page (and not in every folder), use code like this:

fn index(_: &HttpRequest) -> Result<fs::NamedFile> {
    Ok(fs::NamedFile::open("static/index.html")?)
}
...
.resource("/", |r| r.f(index))

P.S. @fafhrd91 ั ะทะฝะฐัŽ, ั‡ั‚ะพ ะ’ั‹ ั…ะพั€ะพัˆะธะน ะฟั€ะพะณั€ะฐะผะผะธัั‚ ะธ ั ัะปัƒัˆะฐะป ะ’ะฐัˆะต ะฒั‹ัั‚ัƒะฟะปะตะฝะธะต ะฟั€ะพ Rust ะธ Python. ะะพ ะผั‹ ะฝะต ะธะดะตะฐะปัŒะฝั‹ ะธ ะผะฝะต ะบะฐะถะตั‚ัั, ั‡ั‚ะพ ะธัะฟะพะปัŒะทะพะฒะฐั‚ัŒ index_file() ะฒะพะพะฑั‰ะต ะฟะปะพั…ะฐั ะธะดะตั. ะ’ะพะทะผะพะถะฝะพ, ัั‚ะพ ะดะพะปะถะฝะพ ั€ะฐะฑะพั‚ะฐั‚ัŒ ะฟะพ ะดั€ัƒะณะพะผัƒ, ะฝะพ ัƒ ะผะตะฝั, ะฝะฐะฟั€ะธะผะตั€, ัั‚ะพ ั€ะฐะฑะพั‚ะฐะตั‚ ะดะปั ะบะฐะถะดะพะน ะฒะปะพะถะตะฝะฝะพะน ะฟะฐะฟะบะธ (ะธะปะธ ะดะปั ะบะฐะถะดะพะณะพ ะทะฐะฟั€ะพัะฐ ะฒ ะฑั€ะฐัƒะทะตั€ะต), ะฝะฐะฟั€ะธะผะตั€ "localhost/somefolder" ะฒะตั€ะฝะตั‚ ะผะฝะต "localhost/somefolder/index.html", ะฐ ั‚ะพั‡ะฝะตะต ะพัˆะธะฑะบัƒ ะพ ั‚ะพะผ, ั‡ั‚ะพ index.html ะฝะต ะฝะฐะนะดะตะฝ (ะพัะพะฑะตะฝะฝะพ ะตัะปะธ ะฟั€ะธะบั€ัƒั‚ะธั‚ัŒ default_handler(p404)). ะัƒะถะฝะพ ัะดะตะปะฐั‚ัŒ ะดะพะบัƒะผะตะฝั‚ะฐั†ะธัŽ ะดะปั index_file ะธะปะธ ะฟะตั€ะตะฟะธัะฐั‚ัŒ ัั‚ะพั‚ ะผะตั‚ะพะด. ะ˜ะปะธ ะฒะพะพะฑั‰ะต ะฒั‹ะฟะธะปะธั‚ัŒ ะตะณะพ, ั‚.ะบ. ะพะฝ ะฟะพะฑัƒะถะดะฐะตั‚ ะฟั€ะพะณั€ะฐะผะผะธัั‚ะพะฒ ะฟะธัะฐั‚ัŒ ะพัˆะธะฑะพั‡ะฝั‹ะน ะบะพะด, ะบะพั‚ะพั€ั‹ะน ั€ะฐะฑะพั‚ะฐะตั‚ ะฝะต ั‚ะฐะบ, ะบะฐะบ ะพะฝะธ ะดัƒะผะฐะปะธ. ะŸะพั‚ะพะผัƒ ั‡ั‚ะพ ะฒะตะทะดะต ะฒ ะฟั€ะธะผะตั€ะฐั… index_file ะธัะฟะพะปัŒะทัƒะตั‚ัั ัะบะพะฑั‹ ะดะปั ั‚ะพะณะพ, ั‡ั‚ะพ ะฑั‹ ะตะณะพ ะฐะฒั‚ะพะผะฐั‚ะธั‡ะตัะบะธ ะฒั‹ะทั‹ะฒะฐั‚ัŒ ะฟั€ะธ ะทะฐะฟั€ะพัะต ะณะปะฐะฒะฝะพะน ัั‚ั€ะฐะฝะธั†ั‹ ัะฐะนั‚ะฐ. ะฅะพั‚ั ะฟะพ ั„ะฐะบั‚ัƒ ะฟะพะปัƒั‡ะฐะตั‚ัั, ั‡ั‚ะพ ัั‚ะพั‚ ั„ะฐะนะป ะดะพะปะถะตะฝ ะฝะฐั…ะพะดะธั‚ัŒัั ะฒ ะบะฐะถะดะพะน ะฒะปะพะถะตะฝะฝะพะน ะฟะฐะฟะบะต, ะบ ะบะพั‚ะพั€ะพะน ะฟั€ะธะผะตะฝะตะฝ .handler()

http-full-proxy calls succeed via curl but fail in browser and postman

playing the the actix-examples/http-full-proxy against httpbin.org (offers lots of REST options to proxy):
cargo run 127.0.0.1 8080 httpbin.org 80
hitting the proxy via curl works: curl -S -v http://127.0.0.1:8080/get
But the same call via Postman (or firefox browser) fails with a page

Could not get any response
There was an error connecting to 127.0.0.1:8080/get.
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Proxy configured incorrectly
Ensure that proxy is configured correctly in Settings > Proxy
Request timeout:
Change request timeout in Settings > General

I confirmed that postman timeout was set to infinite. Also in postman I disabled certificate verification.

I played with filtering the response header values and found that it only works once I filter out both the content-encoding and content-length headers. I appreciate any guidance on what I should look at to fix. Thanks
(Obviously I pulled the example from another call in postmanโ€ฆ 127.0.0.1:8080/get presents the same way as uuid)

Change "plain/text" to "text/plain"

In basics/src/main.rs "test/plain" should be "text/plain":

/// handler with path parameters like `/user/{name}/`
fn with_param(req: HttpRequest) -> HttpResponse {
    println!("{:?}", req);

    HttpResponse::Ok()
        .content_type("test/plain")
        .body(format!("Hello {}!", req.match_info().get("name").unwrap()))
}

In basics/README.md plain/textshould be text/plain:

- [http://localhost:8080/user/bob/](http://localhost:8080/user/bob/) plain/text download

In src/pred.rs "plain/text"should be "plain/text" (https://github.com/actix/actix-web/):

/// Return predicate that matches if all of supplied predicate matches.
///
/// ```rust
/// # extern crate actix_web;
/// use actix_web::{pred, App, HttpResponse};
///
/// fn main() {
///     App::new().resource("/index.html", |r| {
///         r.route()
///             .filter(
///                 pred::All(pred::Get())
///                     .and(pred::Header("content-type", "plain/text")),
///             )
///             .f(|_| HttpResponse::MethodNotAllowed())
///     });
/// }
/// ```

More middleware examples

Hello,

can we put more examples on middleware section for actix-web 1.0.0?
I am currently trying to implement a flash middleware that automatically set and erase flash messages, and an auth check middleware that guard specific routes.

Looking at the middleware examples, I still don't understand how to properly do this. Any help is appreciated. If I can implement it correctly I will send a PR for those flash and auth middleware examples.

Incorrect "heart-beat" comments in websocket examples

websocket/src/client.rs code says that if it doesn't do a heart-beat every 10 seconds, then server will disconnect it. But if I remove the heart-beat, then the client doesn't get disconnected.

The websocket-chat/src/main.rs server tracks heart-beats but doesn't do anything else with them. Again, a comment says "Client must send ping at least once per 10 seconds, otherwise we drop connection." But it doesn't really drop the connection.

Finally, in the websocket-tcp-chat example, both the server and the client do heart-beats, so if the client doesn't do its heart-beat, the server really does drop it.

build is broken (no AlpnError in ssl)

error[E0432]: unresolved import openssl::ssl::AlpnError
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-0.7.3/src/server/srv.rs:23:20
|
23 | use openssl::ssl::{AlpnError, SslAcceptorBuilder};
| ^^^^^^^^^ no AlpnError in ssl

Consider removing yarte example

yarte was recently added into the examples directory. Given the potential licensing issues in regards to askama I'm not sure its wise to support it here.

This thread on reddit details the licensing issues that arose. Particularly comments here, and here. Which seem to indicate that it is indeed a derivative.

The github repo has been deleted and the git history erased. The newer gitlab repo doesn't have any of the history or issues that detailed this unfortunately. Obviously image links aren't great but since the issue was deleted I'll provide a link to an image captured from the original discussion here.

http-proxy example not working (ssl and permanent redirect)

http-proxy does not correctly set up actix-web dependency and depends on https://www.rust-lang.org/en-US/ which is permanently moved.

What happens? Request to /streaming fails.
What was expected? Example working, getting data from proxied request.

Partly reported in #96. Adding rust-tls as feature to actix-web does not work, adding ssl does.

To reproduce:

git clone https://github.com/actix/examples actix-examples
cd actix-examples/http-proxy
# in terminal 1
cargo run --bin proxy-example-server
# in terminal 2
cargo run --bin proxy
# in terminal 3
curl localhost:8080
curl localhost:8080/streaming
> Failed to connect to host: SSL is not supported

Adding ssl:

actix-web = { version = "1.0.0", features=["ssl"] }
curl localhost:8080/streaming -v
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /streaming HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< transfer-encoding: chunked
< date: Mon, 10 Jun 2019 16:01:52 GMT
< 
* Connection #0 to host localhost left intact

Simple file to db example

I'm looking for a simple example that shows how to upload a file to the server and put in in the db. Files are small. Usually less than 100KiB.

There is a multipart example, but it way too complex. I'm looking for something like:

fn add_file((file, state): (Binary, State<AppState>)) -> HttpResponse {
    // do stuff
}

Is it possible?

Feature of diesel example was incorrectly removed

In the update to 1.0.0 alpha, in the commit at : f39a53e an important example was removed. That was that you may have a route which will need to asynchronously communicate to an actor, as well as parsing and manipulating json.

Because this was removed to the trivial sql example, the value of the example as a complete application is diminished. Previously it showed how you would use async, and the correct types to allow a route handler to contact an actor, but now it loses that context and value.

I'd like the DbExecutor actor put back with the SyncArbiter, and the example updated to show how to communicate with actors asynchronously in 1.0.0. with json extractions.

Thanks,

Add example for unit tests

It would extremely useful to see a well-structured test suite, where requests are forged and sent to a test server in order to assert responses content.

Does anyone know an existing project that does that well out there? I would be happy to contribute a small example if there's a model I can be inspired by ;)

Reading POST data is slow (json example)

I've started json example code and tried to send 1.8KB to all endpoints. Everytime request took over 1s (before actually failing due to bad json). I guess reading 1.8KB should take more than few milliseconds (over localhost).

Steps to reproduce:
cd json; cargo run
curl 'http://localhost:8080/extractor2' -X POST -d @Req -H 'Content-Type: application/json'
where req is a file containing 1.8KB of data.

Hello world don't compile

Hi!
I'm trying to run 'hello-world' example.

Those are my steps

$ git clone https://github.com/actix/examples.git
Cloning into 'examples'...
remote: Enumerating objects: 264, done.
remote: Counting objects: 100% (264/264), done.
remote: Compressing objects: 100% (160/160), done.
remote: Total 1558 (delta 65), reused 263 (delta 65), pack-reused 1294
Receiving objects: 100% (1558/1558), 851.46 KiB | 1.54 MiB/s, done.
Resolving deltas: 100% (633/633), done.
$ cd examples/
$ git checkout 1.0
Branch '1.0' set up to track remote branch '1.0' from 'origin'.
Switched to a new branch '1.0'
$ git status
On branch 1.0
Your branch is up to date with 'origin/1.0'.

nothing to commit, working tree clean
$ cd hello-world/
$ cargo run
    Updating crates.io index
    Updating git repository `https://github.com/actix/actix-web.git`
    Updating git repository `https://github.com/actix/actix-http.git`
    Updating git repository `https://github.com/actix/actix-net.git`
   Compiling libc v0.2.50
   Compiling semver-parser v0.7.0
   Compiling autocfg v0.1.2
   Compiling proc-macro2 v0.4.27
   Compiling rand_core v0.4.0
   Compiling unicode-xid v0.1.0
   Compiling byteorder v1.3.1
   Compiling syn v0.15.29
   Compiling stable_deref_trait v1.1.1
   Compiling smallvec v0.6.9
   Compiling cfg-if v0.1.7
   Compiling lazy_static v1.3.0
   Compiling scopeguard v0.3.3
   Compiling slab v0.4.2
   Compiling failure_derive v0.1.5
   Compiling matches v0.1.8
   Compiling futures v0.1.25
   Compiling encoding_index_tests v0.1.4
   Compiling fnv v1.0.6
   Compiling lazycell v1.2.1
   Compiling rustc-demangle v0.1.13
   Compiling percent-encoding v1.0.1
   Compiling memchr v2.2.0
   Compiling version_check v0.1.5
   Compiling cc v1.0.30
   Compiling linked-hash-map v0.4.2
   Compiling serde v1.0.89
   Compiling ryu v0.2.7
   Compiling quick-error v1.2.2
   Compiling regex v1.1.2
   Compiling untrusted v0.6.2
   Compiling crc32fast v1.2.0
   Compiling ucd-util v0.1.3
   Compiling arc-swap v0.3.7
   Compiling safemem v0.3.0
   Compiling httparse v1.3.3
   Compiling itoa v0.4.3
   Compiling void v1.0.2
   Compiling dtoa v0.4.3
   Compiling indexmap v1.0.2
   Compiling string v0.1.3
   Compiling utf8-ranges v1.0.2
   Compiling bitflags v1.0.4
   Compiling sha1 v0.6.0
   Compiling language-tags v0.2.2
   Compiling termcolor v1.0.4
   Compiling rand_core v0.3.1
   Compiling owning_ref v0.4.0
   Compiling rand_pcg v0.1.2
   Compiling rand_chacha v0.1.1
   Compiling rand v0.6.5
   Compiling backtrace v0.3.14
   Compiling semver v0.9.0
   Compiling log v0.4.6
   Compiling unicode-bidi v0.3.4
   Compiling crossbeam-utils v0.6.5
   Compiling thread_local v0.3.6
   Compiling encoding-index-japanese v1.20141219.5
   Compiling encoding-index-tradchinese v1.20141219.5
   Compiling encoding-index-simpchinese v1.20141219.5
   Compiling encoding-index-singlebyte v1.20141219.5
   Compiling encoding-index-korean v1.20141219.5
   Compiling unicode-normalization v0.1.8
   Compiling unicase v2.3.0
   Compiling lru-cache v0.1.1
   Compiling humantime v1.2.0
   Compiling regex-syntax v0.6.5
   Compiling ring v0.13.5
   Compiling miniz-sys v0.1.11
   Compiling brotli-sys v0.3.2
   Compiling rand_xorshift v0.1.1
   Compiling rand_isaac v0.1.1
   Compiling rand_hc v0.1.0
   Compiling lock_api v0.1.5
   Compiling rustc_version v0.2.3
   Compiling tokio-sync v0.1.3
   Compiling actix-service v0.3.3
   Compiling actix-server-config v0.1.0 (https://github.com/actix/actix-net.git#5567fb41)
   Compiling tokio-executor v0.1.6
   Compiling encoding v0.2.33
   Compiling rand_os v0.1.3
   Compiling rand_jitter v0.1.3
   Compiling iovec v0.1.2
   Compiling net2 v0.2.33
   Compiling num_cpus v1.10.0
   Compiling socket2 v0.3.8
   Compiling hostname v0.1.5
   Compiling signal-hook v0.1.8
   Compiling time v0.1.42
   Compiling atty v0.2.11
   Compiling parking_lot_core v0.4.0
   Compiling base64 v0.9.3
   Compiling base64 v0.10.1
   Compiling hashbrown v0.1.8
   Compiling tokio-timer v0.2.10
   Compiling tokio-current-thread v0.1.5
   Compiling quote v0.6.11
   Compiling aho-corasick v0.6.10
   Compiling bytes v0.4.12
   Compiling threadpool v1.7.1
   Compiling mio v0.6.16
   Compiling resolv-conf v0.6.2
   Compiling flate2 v1.0.6
   Compiling mime v0.3.13
   Compiling tokio-io v0.1.12
   Compiling http v0.1.16
   Compiling brotli2 v0.3.2
   Compiling mio-uds v0.6.7
   Compiling tokio-codec v0.1.1
   Compiling parking_lot v0.7.1
   Compiling actix-codec v0.1.1
   Compiling actix-utils v0.3.3
   Compiling tokio-reactor v0.1.9
   Compiling serde_json v1.0.39
   Compiling tokio-tcp v0.1.3
   Compiling tokio-udp v0.1.3
   Compiling actix-rt v0.2.0
   Compiling tokio-signal v0.2.7
   Compiling env_logger v0.6.1
   Compiling actix-server v0.3.1 (https://github.com/actix/actix-net.git#5567fb41)
   Compiling h2 v0.1.16
   Compiling actix-router v0.1.0
   Compiling synstructure v0.10.1
   Compiling enum-as-inner v0.2.1
   Compiling derive_more v0.14.0
   Compiling actix-web-codegen v0.1.0 (https://github.com/actix/actix-web.git?branch=1.0#96804230)
   Compiling idna v0.1.5
   Compiling failure v0.1.5
   Compiling url v1.7.2
   Compiling trust-dns-proto v0.7.1
   Compiling serde_urlencoded v0.5.4
   Compiling cookie v0.11.0
   Compiling trust-dns-resolver v0.11.0-alpha.2
   Compiling actix-connector v0.3.0
   Compiling actix-http v0.1.0 (https://github.com/actix/actix-http.git#64360041)
   Compiling actix-web v1.0.0-alpha.1 (https://github.com/actix/actix-web.git?branch=1.0#96804230)
error[E0277]: the trait bound `actix_server_config::Io<tokio_tcp::stream::TcpStream>: tokio_io::async_read::AsyncRead` is not satisfied
   --> /Users/personale/.cargo/git/checkouts/actix-web-02c803d355aed967/9680423/src/server.rs:241:58
    |
241 |         self.builder = Some(self.builder.take().unwrap().listen(
    |                                                          ^^^^^^ the trait `tokio_io::async_read::AsyncRead` is not implemented for `actix_server_config::Io<tokio_tcp::stream::TcpStream>`
    |
    = note: required because of the requirements on the impl of `actix_service::NewService<actix_server_config::ServerConfig>` for `actix_http::service::service::HttpService<actix_server_config::Io<tokio_tcp::stream::TcpStream>, S, B>`
    = note: required because of the requirements on the impl of `actix_server::services::ServiceFactory` for `[closure@/Users/personale/.cargo/git/checkouts/actix-web-02c803d355aed967/9680423/src/server.rs:244:13: 250:14 cfg:_, factory:_]`

error[E0277]: the trait bound `actix_server_config::Io<tokio_tcp::stream::TcpStream>: tokio_io::async_write::AsyncWrite` is not satisfied
   --> /Users/personale/.cargo/git/checkouts/actix-web-02c803d355aed967/9680423/src/server.rs:241:58
    |
241 |         self.builder = Some(self.builder.take().unwrap().listen(
    |                                                          ^^^^^^ the trait `tokio_io::async_write::AsyncWrite` is not implemented for `actix_server_config::Io<tokio_tcp::stream::TcpStream>`
    |
    = note: required because of the requirements on the impl of `actix_service::NewService<actix_server_config::ServerConfig>` for `actix_http::service::service::HttpService<actix_server_config::Io<tokio_tcp::stream::TcpStream>, S, B>`
    = note: required because of the requirements on the impl of `actix_server::services::ServiceFactory` for `[closure@/Users/personale/.cargo/git/checkouts/actix-web-02c803d355aed967/9680423/src/server.rs:244:13: 250:14 cfg:_, factory:_]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `actix-web`.

To learn more, run the command again with --verbose.
$ rustc --version
rustc 1.32.0 (9fda7c223 2019-01-16)
$ cargo --version
cargo 1.32.0 (8610973aa 2019-01-02)

Where am I wrong?
The master works well

Thanks

(This blocks another PR of mine)

Using an async function with actix-web 1.0

I've been trying for some time now to use an async function with the latest (1.0.0-rc) of actix-web. Doesn't seem possible, and feel like I've exhausted all the different possibilities (via the futures preview compatibility layer ) and no luck so far. An example of doing this would be much appreciated! ๐Ÿ‘

Found an error using Actix::arbiter::start in Arm-linux

build examples/websocket-chat for target: arm-unknown-linux-gnueabi.

thread panic message:

thread 'arbiter:c0b6b3b8-36ec-40c9-ad3d-2708e1610d7c:actor' panicked at 'could not initialize thread_rng: All entropy sources failed (permanently unavailable); cause: OS RNG not yet seeded (not ready yet); cause: Resource temporarily unavailable (os error 11)', C:\Users\whyuud\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rand-0.5.5\src\rngs\thread.rs:84:17

An example for serverless usage

Hi, is it presently possible to use actix-web for serverless?

In other words: the application is invoked to render a single endpoint before terminating.

So, rather than the usual

fn main() {
    let body = server::new(
        || App::new()
            .route("/{id}/{name}/index.html", http::Method::GET, index))
        .bind("127.0.0.1:8080").unwrap()
        .run();
}

I'm looking for something like

fn main() {
    let args = std::env::args().into_iter();
    let method: http::Method = args.next().unwrap_or("GET").parse();
    let path = args.next().unwrap_or("/");

    let body = server::new(
        || App::new()
            .route("/{id}/{name}/index.html", http::Method::GET, index))
        .invoke(method, path)
        .expect("Failed to render path.");

    println!("{}", Responder::new(body));
}

Help on the return type of the prototype of the `move ||`?

I want put the Factory parameter of App::new() into my single file: router.rs, how to declare the return type? Thanks..

HttpServer::new(move || {
        App::new()
        ...
)
  • the following compile failed with error:
/usr/bin/cargo run --color=always --package simple-auth-server --bin simple-auth-server
   Compiling simple-auth-server v0.1.0 (/home/admin/work/ap-server)
error[E0107]: wrong number of type arguments: expected 2, found 0
  --> src/router.rs:18:17
   |
18 | pub fn app() -> App {
   |                 ^^^ expected 2 type arguments

error: aborting due to previous error
///// my router.rs
use actix_web::{App, web, HttpServer};
use actix_web::middleware::{
    identity::{CookieIdentityPolicy, IdentityService},
    Logger,
};
use chrono::Duration;
use actix_files as fs;

use crate::api::{};
use crate::api;
use diesel::r2d2::ConnectionManager;
use diesel::PgConnection;
use actix::{Addr, SyncArbiter};
use crate::models::DbExecutor;
use actix_web::dev::{MessageBody, Body};
//use actix_web::app_service::{AppEntry};

pub fn app() -> App {
    // secret is a random minimum 32 bytes long base 64 string
    let secret: String = std::env::var("SECRET_KEY").unwrap_or_else(|_| "0123".repeat(8));
    let domain: String = std::env::var("DOMAIN").unwrap_or_else(|_| "localhost".to_string());

    let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
    // create db connection pool
    let manager = ConnectionManager::<PgConnection>::new(database_url);
    let pool = r2d2::Pool::builder()
        .build(manager)
        .expect("Failed to create pool.");

    let address: Addr<DbExecutor> =
        SyncArbiter::start(4, move || DbExecutor(pool.clone()));

    App::new()
        .data(address.clone())
        .wrap(Logger::default())
        .wrap(IdentityService::new(
            CookieIdentityPolicy::new(secret.as_bytes())
                .name("auth")
                .path("/")
                .domain(domain.as_str())
                .max_age_time(Duration::days(1))
                .secure(false), // this can only be true if you have https
        ))
        // everything under '/api/' route
        .service(
            web::scope("/api")
                // routes for authentication
                .service(
                    web::resource("/auth")
                        .route(web::post().to_async(api::auth_routes::login))
                        .route(web::delete().to(api::auth_routes::logout))
                        .route(web::get().to_async(api::auth_routes::get_me)),
                )
                // routes to invitation
                .service(
                    web::resource("/invitation").route(
                        web::post().to_async(api::invitation_routes::register_email),
                    ),
                )
                // routes to register as a user after the
                .service(
                    web::resource("/register/{invitation_id}")
                        .route(web::post().to_async(api::register_routes::register_user)),
                ),
        )
        // serve static files
        .service(fs::Files::new("/", "./static/").index_file("index.html"))
}

examples's StreamHandler is sync, how can I be async.

StreamHandler use wait is sync, how can I be async.

impl StreamHandler<ws::Message, ws::ProtocolError> for WsChatSession {
    fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
    ctx.state()
        .addr
        .send(server::ListRooms)
        .into_actor(self)
        .then(|res, _, ctx| {
            match res {
                Ok(rooms) => {
                    for room in rooms {
                        ctx.text(room);
                    }
                }
                _ => println!("Something is wrong"),
            }
            fut::ok(())
        })
        .wait(ctx)
    // .wait(ctx) pauses all events in context,
    // so actor wont receive any new messages until it get list
    // of rooms back
  }
}

websocket-tcp-chat does not open TCP listener

Not sure it's a bug in the example, in Actix or on my Mac but I cannot get the example to listen on TCP port 12345. session::TcpServer::new is never executed for some reason.

With the following change it works:

-    Arbiter::new().exec(move || {
-        session::TcpServer::new("127.0.0.1:12345", srv);
-        Ok::<_, ()>(())
-    });
+    session::TcpServer::new("127.0.0.1:12345", srv);

JSON post examples sending to other actors

There are no example of using a JSON post where the request is sent to another actor, and the json deserialised correctly. The workflow in mind is:

index(request<AppState>) -> ... {
    req.payload()
        .from_err()
        .fold( ... bytes -> body)
        .and_then(body)  {
             let result_obj = serde_json::from_slice::<MyStruct>(&body);
             // send a custom error on Err(e) in result_obj
             // send the obj to another actor and then respond with json
             // IE request.state().actor.send().... 
        }
}

This is a reasonably complex example, incorporating many different components, and would be really important to have because there is no current example that demonstrates these components working together (json error handling and response, communicating to an actor, and handling the post). There are small elements of each through out the examples project, but without having a complete, tied together example it's really difficult to tie everything together.

Add example showing how to access shared state from middleware in 1.0.0-alpha.6

Accessing shared state in handlers is demonstrated in https://github.com/actix/examples/blob/815e34f32ded77f73145fb0373a060b22636f689/state/src/main.rs

And with the way middleware worked previously, you could access shared state in the middleware as such: https://stackoverflow.com/questions/50428385/application-state-access-from-an-actix-web-application-middleware/50428541#50428541

But with the way middleware works now, as demonstrated in https://github.com/actix/examples/blob/09b0188ff99e872898793bd815382a4105219b77/middleware/src/redirect.rs. it is not apparent how one would access shared state from middleware.

Adding an example showing how to access shared state from middleware in 1.0.0-alpha.6 would be immensly helpful.

basics example: wrong index.html or the proper handler is missing

The index.html in the "basics" example contains a chat form which trying to establish a websocket connection using the following url: "127.0.0.1:8080/ws" when I click the "Connect" button, but in the main.rs there is no resource named "/ws" and the ws module even isn't imported. So I get an "Error during WebSocket handshake: Unexpected response code: 404" and can't do anything useful with this chat window.

HTTP/2 example and Heroku deployment.

I am trying to use deploy one of the actix-web examples that offers HTTP/2 support in Heroku, having slightly modified it to listen at the provided $PORT number and the way in which certs are loaded -- rather than read from a file, it obtains the public and private key from the environment.

The problem being is that, on each request, the Heroku router logs that the connection is closed without a response.

heroku[router]: 
at=error
code=H13
desc="Connection closed without response"
method=GET
status=503
bytes=0
protocol=https

As it worked locally, I suspect the issue is at my dyno's configuration, which is a Hobby ($7/mo), especially at the certs section. As the application expects to receive the cert info from the environmental variables and having that Heroku does not provide you access to their certificates (e.g cert for xxxxx.herokuapp.com), I bought a domain name with the hopes of generating my own. I did, using the following page.

With a self-generated cert, I've tried so far the following, resulting in any of cases in the following errors:

  1. To provide the same pair of keys to the dyno and application. The logs yield the error mentioned above.
  2. Not to provide SSL configuration to the dyno, but to the application. Therefore, https access is disabled and the dyno is not even hit.
  3. Not to provide certs configuration to the app, but to the dyno. The app crashes on boot time.

However, if I remove the related rustls lines, everything works smoothly, but the protocol used is HTTP/1.1.

Do you have any idea that might make it work in Heroku using HTTP/2?

Thanks!

less and less hello world qps with the increasing of times

use actix_web::{web, App,  HttpServer};
fn main() -> std::io::Result<()> {

    HttpServer::new(|| {
        App::new()
            .service(web::resource("/").to(|| "Hello world!"))
    })
    .bind("127.0.0.1:8080")?
    .run()
}
cargo 1.35.0-nightly (0e35bd8af 2019-03-13)
release: 1.35.0
commit-hash: 0e35bd8af0ec72d3225c4819b330b94628f0e9d0
commit-date: 2019-03-13

rustc 1.35.0-nightly (33ef0bad2 2019-03-27)
binary: rustc
commit-hash: 33ef0bad21d6bb646c7c3ab0dbf381ca96c324bf
commit-date: 2019-03-27
host: x86_64-apple-darwin
release: 1.35.0-nightly
LLVM version: 8.0

1 run

wrk http://127.0.0.1:8080/
Running 10s test @ http://127.0.0.1:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    90.31us   57.75us   2.93ms   94.97%
    Req/Sec    38.70k     7.21k   52.25k    60.40%
  777590 requests in 10.10s, 95.66MB read
Requests/sec:  76993.74
Transfer/sec:      9.47MB

2 run

wrk http://127.0.0.1:8080/
Running 10s test @ http://127.0.0.1:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    83.34us   62.76us   7.28ms   97.60%
    Req/Sec    21.88k     1.60k   24.74k    70.30%
  439619 requests in 10.10s, 54.08MB read
Requests/sec:  43528.79
Transfer/sec:      5.36MB

3 run

wrk http://127.0.0.1:8080/
Running 10s test @ http://127.0.0.1:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    91.76us   94.36us   9.70ms   97.83%
    Req/Sec    19.91k     9.99k   31.64k    54.46%
  400041 requests in 10.10s, 49.21MB read
Requests/sec:  39606.58
Transfer/sec:      4.87MB

4 run

wrk http://127.0.0.1:8080/
Running 10s test @ http://127.0.0.1:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    76.07us   57.92us   5.67ms   99.76%
    Req/Sec    12.46k   810.37    13.02k    96.04%
  125228 requests in 10.10s, 15.41MB read
Requests/sec:  12397.45
Transfer/sec:      1.53MB

5 run

wrk http://127.0.0.1:8080/
Running 10s test @ http://127.0.0.1:8080/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     0.00us    0.00us   0.00us     nan%
    Req/Sec     0.00      0.00     0.00       nan%
  0 requests in 10.08s, 0.00B read
Requests/sec:      0.00
Transfer/sec:       0.00B

Juniper example not working

Hi! I'm trying to run the juniper example, but the schema does not seem to be loaded properly in graphiql and I get 404s when trying to run a query.

screen shot 2018-08-17 at 4 56 37 pm

I'm not familiar with Juniper nor Actix so it would take me a while to debug. Any idea what's broken? Thank you!

hello-world example does not build

subuser@c0b8b1978224fe02d0a1:/pwd/src/play/examples/hello-world$ cargo build
   Compiling semver-parser v0.7.0
   Compiling libc v0.2.54
   Compiling autocfg v0.1.2
   Compiling rand_core v0.4.0
   Compiling proc-macro2 v0.4.30
   Compiling unicode-xid v0.1.0
   Compiling byteorder v1.3.1
   Compiling cc v1.0.36
   Compiling stable_deref_trait v1.1.1
   Compiling syn v0.15.34
   Compiling cfg-if v0.1.7
   Compiling lazy_static v1.3.0
   Compiling scopeguard v0.3.3
   Compiling smallvec v0.6.9
   Compiling encoding_index_tests v0.1.4
   Compiling fnv v1.0.6
   Compiling lazycell v1.2.1
   Compiling slab v0.4.2
   Compiling futures v0.1.27
   Compiling matches v0.1.8
   Compiling failure_derive v0.1.5
   Compiling rustc-demangle v0.1.14
   Compiling percent-encoding v1.0.1
   Compiling num-traits v0.2.6
   Compiling version_check v0.1.5
   Compiling memchr v2.2.0
   Compiling ryu v0.2.8
   Compiling void v1.0.2
   Compiling quick-error v1.2.2
   Compiling crc32fast v1.2.0
   Compiling serde v1.0.91
   Compiling linked-hash-map v0.5.2
   Compiling num-integer v0.1.39
   Compiling itoa v0.4.4
   Compiling regex v1.1.6
   Compiling arc-swap v0.3.11
   Compiling ucd-util v0.1.3
   Compiling httparse v1.3.3
   Compiling spin v0.5.0
   Compiling indexmap v1.0.2
   Compiling dtoa v0.4.4
   Compiling untrusted v0.6.2
   Compiling string v0.1.3
   Compiling either v1.5.2
   Compiling utf8-ranges v1.0.2
   Compiling language-tags v0.2.2
   Compiling copyless v0.1.2
   Compiling sha1 v0.6.0
   Compiling hashbrown v0.2.2
   Compiling bitflags v1.0.4
   Compiling termcolor v1.0.4
   Compiling rand_core v0.3.1
   Compiling rand_jitter v0.1.4
   Compiling semver v0.9.0
   Compiling rand_pcg v0.1.2
   Compiling rand_chacha v0.1.1
   Compiling rand v0.6.5
   Compiling backtrace v0.3.15
   Compiling owning_ref v0.4.0
   Compiling log v0.4.6
   Compiling crossbeam-utils v0.6.5
   Compiling thread_local v0.3.6
   Compiling encoding-index-tradchinese v1.20141219.5
   Compiling encoding-index-korean v1.20141219.5
   Compiling encoding-index-simpchinese v1.20141219.5
   Compiling encoding-index-japanese v1.20141219.5
   Compiling encoding-index-singlebyte v1.20141219.5
   Compiling unicode-bidi v0.3.4
   Compiling unicode-normalization v0.1.8
   Compiling backtrace-sys v0.1.28
   Compiling brotli-sys v0.3.2
   Compiling miniz-sys v0.1.11
   Compiling ring v0.14.6
   Compiling unicase v2.4.0
   Compiling humantime v1.2.0
   Compiling lru-cache v0.1.2
   Compiling tokio-sync v0.1.5
   Compiling actix-service v0.3.6
   Compiling regex-syntax v0.6.6
   Compiling rand_hc v0.1.0
   Compiling rand_xorshift v0.1.1
   Compiling rand_isaac v0.1.1
   Compiling lock_api v0.1.5
   Compiling rustc_version v0.2.3
   Compiling tokio-executor v0.1.7
   Compiling encoding v0.2.33
   Compiling rand_os v0.1.3
   Compiling iovec v0.1.2
   Compiling net2 v0.2.33
   Compiling num_cpus v1.10.0
   Compiling hostname v0.1.5
   Compiling socket2 v0.3.9
   Compiling signal-hook-registry v1.0.1
   Compiling time v0.1.42
   Compiling atty v0.2.11
   Compiling base64 v0.10.1
   Compiling parking_lot_core v0.4.0
   Compiling quote v0.6.12
   Compiling tokio-timer v0.2.10
   Compiling tokio-current-thread v0.1.6
   Compiling aho-corasick v0.7.3
   Compiling bytes v0.4.12
   Compiling threadpool v1.7.1
   Compiling mio v0.6.16
   Compiling resolv-conf v0.6.2
   Compiling signal-hook v0.1.9
   Compiling chrono v0.4.6
   Compiling flate2 v1.0.7
   Compiling mime v0.3.13
   Compiling brotli2 v0.3.2
   Compiling tokio-io v0.1.12
   Compiling http v0.1.17
   Compiling string v0.2.0
   Compiling mio-uds v0.6.7
   Compiling idna v0.1.5
   Compiling tokio-codec v0.1.1
   Compiling url v1.7.2
   Compiling h2 v0.1.18
   Compiling env_logger v0.6.1
   Compiling actix-codec v0.1.2
   Compiling parking_lot v0.7.1
   Compiling synstructure v0.10.1
   Compiling enum-as-inner v0.2.1
   Compiling serde_derive v1.0.91
   Compiling derive_more v0.14.0
   Compiling actix-web-codegen v0.1.0-beta.1
   Compiling actix-utils v0.3.5
   Compiling tokio-reactor v0.1.9
   Compiling tokio-tcp v0.1.3
   Compiling tokio-udp v0.1.3
   Compiling tokio-signal v0.2.7
   Compiling failure v0.1.5
   Compiling actix-server-config v0.1.1
   Compiling actix-threadpool v0.1.0
   Compiling trust-dns-proto v0.7.3
   Compiling actix-rt v0.2.2
error[E0004]: non-exhaustive patterns: `_` not covered
   --> /home/subuser/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.7.3/src/rr/rdata/tlsa.rs:134:15
    |
134 |         match usage {
    |               ^^^^^ pattern `_` not covered

error[E0004]: non-exhaustive patterns: `_` not covered
   --> /home/subuser/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.7.3/src/rr/rdata/tlsa.rs:193:15
    |
193 |         match selector {
    |               ^^^^^^^^ pattern `_` not covered

error[E0004]: non-exhaustive patterns: `_` not covered
   --> /home/subuser/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.7.3/src/rr/rdata/tlsa.rs:254:15
    |
254 |         match matching {
    |               ^^^^^^^^ pattern `_` not covered

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0004`.
error: Could not compile `trust-dns-proto`.
warning: build failed, waiting for other jobs to finish...
error: build failed
subuser@c0b8b1978224fe02d0a1:/pwd/src/play/examples/hello-world$ git log -n 1
commit 68509a7eaf4b382aa814d250c0db838c83a2834d (HEAD -> master, origin/master, origin/HEAD)
Author: huang.xiangdong <[email protected]>
Date:   Mon May 6 15:26:42 2019 +0800

    use absolute path
subuser@c0b8b1978224fe02d0a1:/pwd/src/play/examples/hello-world$ cargo --version
cargo 1.32.0
subuser@c0b8b1978224fe02d0a1:/pwd/src/play/examples/hello-world$ rustc --version
rustc 1.32.0

Perhaps it would help if the examples included Cargo.lock files so that we would have a known good dependency DAG?

Json post examples don't return errors on invalid json

When using the json post examples, misformed json returns no errors:

actix-examples/json I0> curl --header "Content-Type: application/json" --request POST --data '{ "invalid": "data" }'  http://127.0.0.1:8080/
actix-examples/json I0> echo $?
0

actix-examples/json I0> curl -i --header "Content-Type: application/json" --request POST --data '{ "invalid": "data" }'  http://127.0.0.1:8080/
HTTP/1.1 400 Bad Request
content-length: 0
date: Sun, 11 Nov 2018 23:43:04 GMT

 WARN 2018-11-11T23:41:00Z: actix_web::pipeline: Error occured during request handling: Json deserialize error: missing field `name` at line 1 column 21
 INFO 2018-11-11T23:41:00Z: actix_web::middleware::logger: 127.0.0.1:51680 "POST / HTTP/1.1" 400 0 "-" "curl/7.61.1" 0.001901

Curl should receive the message about why the json was invalid. This way the client can improve their behaviour on malformed requests.

The index_manual type is the most likely to be able to support this workflow.

SSL not supported in http-proxy

When I run the http-proxy example, I used curl http://127.0.0.1:8080/streaming, I got an error message:
ERROR 2019-03-28T09:34:05Z: actix_web::pipeline: Error occurred during request handling, status: 502 Bad Gateway Failed to connect to host: SSL is not supported
INFO 2019-03-28T09:34:05Z: actix_web::middleware::logger: 127.0.0.1:52863 "GET /streaming HTTP/1.1" 502 0 "-" "curl/7.54.0" 0.001003

Is there something I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.