Skip to content

Running the example gives a Content Encoding Error #18

@jakewilliami

Description

@jakewilliami

Example main.rs from #17:

use awc::Client;

use actix_web::{get, web, HttpResponse, App, HttpServer};

use actix_proxy::{IntoHttpResponse, SendRequestError};

#[get("/{url:.*}")]
async fn proxy(
    path: web::Path<(String,)>,
    client: web::Data<Client>,
) -> Result<HttpResponse, SendRequestError> {
    let (url,) = path.into_inner();

    let url = format!("https://duckduckgo.com/{url}");

    // here we use `IntoHttpResponse` to return the request to
    // duckduckgo back to the client that called this endpoint
    Ok(client.get(&url).send().await?.into_http_response())
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .app_data(web::Data::new(Client::default())) // This is the important line
            .service(proxy)
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

And example Cargo.toml adapted from #2:

[package]
name = "test-server"
version = "0.1.0"
edition = "2021"

[dependencies]
actix-proxy = "0.2.0"
actix-web = { version = "^4.3.0" }
awc = { version = "^3.1.0", features = ["openssl"] }
openssl = { version = "^0.10.32" }

However, I get a Conent Encoding Error:

Image

Is there something I'm doing wrong?

I saw @Sleepful's comment and CORS Anywhere is essentially the functionality I want to emulate, but using Actix. You could entertain the notion that my company blocked Connections so I was hoping to create a proxy to it on an existing website I have whose server is running on Actix. That might bypass the hypothetical block...

P.S., thank you for your work on this package. It looks really promising. I have also seen redirection.io's Actix Proxy, but it does a lot of magic-y things. I like that with this package I can still easily specify the route, for example. It seems to meld well with base Actix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions