Skip to content

Commit 64aa70f

Browse files
authored
Merge pull request #330 from umccr/feat/suppressed-response
feat: suppressed response and fixes
2 parents 03d77c7 + c6d06b1 commit 64aa70f

File tree

31 files changed

+1615
-542
lines changed

31 files changed

+1615
-542
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

htsget-actix/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ default = []
2626
actix-web = { version = "4", features = ["rustls-0_23"] }
2727
rustls = "0.23"
2828
actix-cors = "0.7"
29+
actix-utils = "3"
2930
http_1 = { package = "http", version = "1" }
3031
http = "0.2"
3132
serde = { version = "1", features = ["derive"] }

htsget-actix/benches/request_benchmarks.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ fn criterion_benchmark(c: &mut Criterion) {
230230
tags: None,
231231
notags: None,
232232
regions: None,
233+
encryption_scheme: None,
233234
};
234235
bench_pair(
235236
&mut group,
@@ -250,6 +251,7 @@ fn criterion_benchmark(c: &mut Criterion) {
250251
start: None,
251252
end: None,
252253
}]),
254+
encryption_scheme: None,
253255
};
254256
bench_pair(
255257
&mut group,
@@ -277,6 +279,7 @@ fn criterion_benchmark(c: &mut Criterion) {
277279
end: Some(5008321),
278280
},
279281
]),
282+
encryption_scheme: None,
280283
};
281284
bench_pair(
282285
&mut group,
@@ -297,6 +300,7 @@ fn criterion_benchmark(c: &mut Criterion) {
297300
start: Some(1),
298301
end: Some(153),
299302
}]),
303+
encryption_scheme: None,
300304
};
301305
bench_pair(
302306
&mut group,
@@ -317,6 +321,7 @@ fn criterion_benchmark(c: &mut Criterion) {
317321
start: None,
318322
end: None,
319323
}]),
324+
encryption_scheme: None,
320325
};
321326
bench_pair(
322327
&mut group,

htsget-actix/src/handlers/get.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ use actix_web::{
44
HttpRequest, Responder,
55
web::{Data, Path, Query},
66
};
7-
use tracing::info;
8-
use tracing::instrument;
9-
107
use htsget_http::{Endpoint, get};
118
use htsget_search::HtsGet;
9+
use tracing::info;
10+
use tracing::instrument;
1211

12+
use super::handle_response;
1313
use crate::AppState;
1414
use crate::handlers::extract_request;
1515

16-
use super::handle_response;
17-
1816
/// GET request reads endpoint
1917
#[instrument(skip(app_state))]
2018
pub async fn reads<H: HtsGet + Clone + Send + Sync + 'static>(
@@ -27,7 +25,15 @@ pub async fn reads<H: HtsGet + Clone + Send + Sync + 'static>(
2725

2826
info!(request = ?request, "reads endpoint GET request");
2927

30-
handle_response(get(app_state.get_ref().htsget.clone(), request, Endpoint::Reads).await)
28+
handle_response(
29+
get(
30+
app_state.get_ref().htsget.clone(),
31+
request,
32+
Endpoint::Reads,
33+
app_state.auth.clone(),
34+
)
35+
.await,
36+
)
3137
}
3238

3339
/// GET request variants endpoint
@@ -47,6 +53,7 @@ pub async fn variants<H: HtsGet + Clone + Send + Sync + 'static>(
4753
app_state.get_ref().htsget.clone(),
4854
request,
4955
Endpoint::Variants,
56+
app_state.auth.clone(),
5057
)
5158
.await,
5259
)

htsget-actix/src/handlers/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use std::collections::HashMap;
22

33
use actix_web::web::{Path, Query};
44
use actix_web::{Either, HttpRequest, Responder, http::StatusCode};
5-
use http::{HeaderMap as HttpHeaderMap, HeaderName, Method};
6-
75
use htsget_config::types::{JsonResponse, Request};
86
use htsget_http::Result;
7+
use http::{HeaderMap as HttpHeaderMap, HeaderName, Method};
98
use pretty_json::PrettyJson;
109

1110
pub use crate::handlers::service_info::{
@@ -16,7 +15,7 @@ pub mod get;
1615
pub mod post;
1716
pub mod service_info;
1817

19-
mod pretty_json;
18+
pub(crate) mod pretty_json;
2019

2120
pub(crate) struct HeaderMap(HttpHeaderMap);
2221

htsget-actix/src/handlers/post.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@ use actix_web::{
55
HttpRequest, Responder,
66
web::{Data, Json, Path},
77
};
8-
use tracing::info;
9-
use tracing::instrument;
10-
118
use htsget_http::{Endpoint, PostRequest, post};
129
use htsget_search::HtsGet;
10+
use tracing::info;
11+
use tracing::instrument;
1312

13+
use super::{extract_request, handle_response};
1414
use crate::AppState;
15-
use crate::handlers::extract_request;
16-
17-
use super::handle_response;
1815

1916
/// POST request reads endpoint
2017
#[instrument(skip(app_state))]
2118
pub async fn reads<H: HtsGet + Clone + Send + Sync + 'static>(
2219
request: Query<HashMap<String, String>>,
23-
body: Json<PostRequest>,
2420
path: Path<String>,
2521
http_request: HttpRequest,
22+
body: Json<PostRequest>,
2623
app_state: Data<AppState<H>>,
2724
) -> impl Responder {
2825
let request = extract_request(request, path, http_request);
@@ -35,6 +32,7 @@ pub async fn reads<H: HtsGet + Clone + Send + Sync + 'static>(
3532
body.into_inner(),
3633
request,
3734
Endpoint::Reads,
35+
app_state.auth.clone(),
3836
)
3937
.await,
4038
)
@@ -44,9 +42,9 @@ pub async fn reads<H: HtsGet + Clone + Send + Sync + 'static>(
4442
#[instrument(skip(app_state))]
4543
pub async fn variants<H: HtsGet + Clone + Send + Sync + 'static>(
4644
request: Query<HashMap<String, String>>,
47-
body: Json<PostRequest>,
4845
path: Path<String>,
4946
http_request: HttpRequest,
47+
body: Json<PostRequest>,
5048
app_state: Data<AppState<H>>,
5149
) -> impl Responder {
5250
let request = extract_request(request, path, http_request);
@@ -59,6 +57,7 @@ pub async fn variants<H: HtsGet + Clone + Send + Sync + 'static>(
5957
body.into_inner(),
6058
request,
6159
Endpoint::Variants,
60+
app_state.auth.clone(),
6261
)
6362
.await,
6463
)

htsget-actix/src/handlers/pretty_json.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@ use serde::Serialize;
44

55
pub struct PrettyJson<T>(pub T);
66

7+
impl<T> TryFrom<PrettyJson<T>> for String
8+
where
9+
T: Serialize,
10+
{
11+
type Error = serde_json::Error;
12+
13+
fn try_from(json: PrettyJson<T>) -> Result<Self, Self::Error> {
14+
let mut body = serde_json::to_string_pretty(&json.0)?;
15+
body.push('\n');
16+
17+
Ok(body)
18+
}
19+
}
20+
721
impl<T: Serialize> Responder for PrettyJson<T> {
822
type Body = BoxBody;
923

1024
fn respond_to(self, _: &HttpRequest) -> HttpResponse {
11-
let mut body = match serde_json::to_string_pretty(&self.0) {
25+
let body = match String::try_from(self) {
1226
Ok(body) => body,
13-
Err(e) => return HttpResponse::from_error(e),
27+
Err(err) => return HttpResponse::from_error(err),
1428
};
15-
body.push('\n');
1629

1730
HttpResponse::build(StatusCode::OK)
1831
.content_type("application/json")

0 commit comments

Comments
 (0)