Skip to content

implement IntoHttpResponse for <SendClientRequest as Future>::Output  #4

@jofas

Description

@jofas

This should allow us to write something even more concise than is currently supported. I hope this code will work with the additional trait implementation:

use awc::Client;

use actix_web::{get, web, Responder};

use actix_proxy::IntoHttpResponse;

#[get("/{url:.*}")]
async fn proxy(
  path: web::Path<(String,)>,
  client: web::Data<Client>,
) -> impl Responder {
  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
  client.get(&url).send().await.into_http_response()
}

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