Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
staszek-krotki committed Jan 15, 2024
1 parent 6e07db5 commit 04bcd84
Showing 1 changed file with 2 additions and 41 deletions.
43 changes: 2 additions & 41 deletions core/activity/src/http_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use actix_http::Method;
use actix_web::http::header;
use actix_web::web::{Bytes, Json};
use actix_web::web::Json;
use actix_web::{web, HttpRequest, HttpResponse};
use futures::prelude::*;
use serde_json::{Map, Value};

use ya_client_model::market::Role;
use ya_persistence::executor::DbExecutor;
use ya_service_api_web::middleware::Identity;

use crate::common::*;
use gsb_http_proxy::{GsbHttpCall, GsbHttpCallEvent, HttpProxyStatusError};
use gsb_http_proxy::GsbHttpCall;
use ya_core_model::activity;
use ya_core_model::net::RemoteEndpoint;

Expand Down Expand Up @@ -88,41 +87,3 @@ async fn proxy_http_request(
.content_type(mime::TEXT_EVENT_STREAM.essence_str())
.streaming(stream))
}

fn invoke<
T: Stream<Item = Result<Result<GsbHttpCallEvent, HttpProxyStatusError>, ya_service_bus::Error>>
+ Unpin,
F: FnOnce(GsbHttpCall) -> T,
>(
body: Option<Map<String, Value>>,
method: Method,
url: String,
trigger_stream: F,
) -> impl Stream<Item = Result<Bytes, actix_web::Error>> + Unpin + Sized {
let path = if let Some(stripped_url) = url.strip_prefix('/') {
stripped_url.to_string()
} else {
url
};

let msg = GsbHttpCall {
method: method.to_string(),
path,
body,
};

let stream = trigger_stream(msg);

stream
.map(|item| match item {
Ok(result) => result,
Err(e) => Err(HttpProxyStatusError::from(e)),
})
.map(move |result| {
let msg = match result {
Ok(r) => r.msg,
Err(e) => format!("Error {}", e),
};
Ok::<Bytes, actix_web::Error>(Bytes::from(msg))
})
}

0 comments on commit 04bcd84

Please sign in to comment.