Skip to content

Commit 74414da

Browse files
committed
Auto merge of #680 - Mark-Simulacrum:bump-deps, r=Mark-Simulacrum
Bump deps Moves us off old hyper...
2 parents f12b120 + 23e43f2 commit 74414da

File tree

9 files changed

+283
-1204
lines changed

9 files changed

+283
-1204
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ opt-level = 0
1010

1111
[dependencies]
1212
base64 = "0.20.0"
13-
bytes = "0.4.9"
14-
bytes_1 = { version = "1", package = "bytes" }
13+
bytes = "1"
1514
chrono = { version = "0.4", features = ["serde"] }
1615
crates-index = "0.18"
1716
crossbeam-utils = "0.8"
@@ -21,8 +20,8 @@ docsrs-metadata = { git = "https://github.com/rust-lang/docs.rs/" }
2120
dotenv = "0.15"
2221
failure = "0.1.3"
2322
flate2 = "1"
24-
http = "0.1.10"
25-
hyper = "0.12.8"
23+
http = "0.2"
24+
hyper = "0.14"
2625
lazy_static = "1.0"
2726
mime = "0.3.1"
2827
minifier = { version = "0.2", features = ["html"] }
@@ -43,7 +42,7 @@ tera = "0.11.7"
4342
toml = "0.4.6"
4443
url = "2"
4544
walkdir = "2"
46-
warp = "0.1.9"
45+
warp = "0.3"
4746
log = "0.4.6"
4847
env_logger = "0.10.0"
4948
hmac = "0.12"

src/report/s3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl ReportWriter for S3Writer {
108108
};
109109

110110
let chunk_size = 20 * 1024 * 1024;
111-
let bytes = bytes_1::Bytes::from(s);
111+
let bytes = bytes::Bytes::from(s);
112112
let mut part = 1;
113113
let mut start = 0;
114114
let mut parts = aws_sdk_s3::model::CompletedMultipartUpload::builder();

src/server/auth.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ pub fn auth_filter(
8282
token_type: TokenType,
8383
) -> impl Filter<Extract = (AuthDetails,), Error = Rejection> + Clone {
8484
warp::header::headers_cloned().and_then(move |headers| {
85-
match check_auth(&data, &headers, token_type) {
86-
Some(details) => Ok(details),
87-
None => Err(warp::reject::custom(HttpError::Forbidden.compat())),
85+
let data = data.clone();
86+
async move {
87+
match check_auth(&data, &headers, token_type) {
88+
Some(details) => Ok(details),
89+
None => Err(warp::reject::custom(HttpError::Forbidden)),
90+
}
8891
}
8992
})
9093
}

src/server/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub enum HttpError {
3737
Forbidden,
3838
}
3939

40+
impl warp::reject::Reject for HttpError {}
41+
4042
#[derive(Clone)]
4143
pub struct Data {
4244
pub config: Config,
@@ -135,7 +137,12 @@ pub fn run(config: Config, bind: SocketAddr) -> Fallible<()> {
135137
},
136138
);
137139

138-
warp::serve(routes).run(bind);
140+
let rt = tokio::runtime::Builder::new_multi_thread()
141+
.enable_all()
142+
.build()?;
143+
rt.block_on(async move {
144+
warp::serve(routes).run(bind).await;
145+
});
139146

140147
Ok(())
141148
}

src/server/routes/agent.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::server::messages::Message;
88
use crate::server::{Data, GithubData, HttpError};
99
use crossbeam_channel::Sender;
1010
use failure::Compat;
11-
use http::{Response, StatusCode};
11+
use http::Response;
1212
use hyper::Body;
1313
use std::collections::HashMap;
1414
use std::sync::{Arc, Condvar, Mutex};
@@ -32,46 +32,46 @@ pub fn routes(
3232
let mutex_filter = warp::any().map(move || mutex.clone());
3333
let github_data_filter = warp::any().map(move || github_data.clone());
3434

35-
let config = warp::post2()
35+
let config = warp::post()
3636
.and(warp::path("config"))
3737
.and(warp::path::end())
3838
.and(warp::body::json())
3939
.and(data_filter.clone())
4040
.and(auth_filter(data.clone(), TokenType::Agent))
4141
.map(endpoint_config);
4242

43-
let next_experiment = warp::post2()
43+
let next_experiment = warp::post()
4444
.and(warp::path("next-experiment"))
4545
.and(warp::path::end())
4646
.and(mutex_filter.clone())
4747
.and(github_data_filter)
4848
.and(auth_filter(data.clone(), TokenType::Agent))
4949
.map(endpoint_next_experiment);
5050

51-
let next_crate = warp::post2()
51+
let next_crate = warp::post()
5252
.and(warp::path("next-crate"))
5353
.and(warp::path::end())
5454
.and(warp::body::json())
5555
.and(data_filter.clone())
5656
.and(auth_filter(data.clone(), TokenType::Agent))
5757
.map(endpoint_next_crate);
5858

59-
let record_progress = warp::post2()
59+
let record_progress = warp::post()
6060
.and(warp::path("record-progress"))
6161
.and(warp::path::end())
6262
.and(warp::body::json())
6363
.and(data_filter.clone())
6464
.and(auth_filter(data.clone(), TokenType::Agent))
6565
.map(endpoint_record_progress);
6666

67-
let heartbeat = warp::post2()
67+
let heartbeat = warp::post()
6868
.and(warp::path("heartbeat"))
6969
.and(warp::path::end())
7070
.and(data_filter)
7171
.and(auth_filter(data.clone(), TokenType::Agent))
7272
.map(endpoint_heartbeat);
7373

74-
let error = warp::post2()
74+
let error = warp::post()
7575
.and(warp::path("error"))
7676
.and(warp::path::end())
7777
.and(warp::body::json())
@@ -355,10 +355,10 @@ fn handle_results(resp: Fallible<Response<Body>>) -> Response<Body> {
355355
}
356356
}
357357

358-
fn handle_errors(err: Rejection) -> Result<Response<Body>, Rejection> {
359-
let error = if let Some(compat) = err.find_cause::<Compat<HttpError>>() {
358+
async fn handle_errors(err: Rejection) -> Result<Response<Body>, Rejection> {
359+
let error = if let Some(compat) = err.find::<Compat<HttpError>>() {
360360
Some(*compat.get_ref())
361-
} else if let StatusCode::NOT_FOUND | StatusCode::METHOD_NOT_ALLOWED = err.status() {
361+
} else if err.is_not_found() {
362362
Some(HttpError::NotFound)
363363
} else {
364364
None

src/server/routes/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn routes(
1212
) -> impl Filter<Extract = (Response<Body>,), Error = Rejection> + Clone {
1313
let data_filter = warp::any().map(move || data.clone());
1414

15-
warp::get2()
15+
warp::get()
1616
.and(warp::path::end())
1717
.and(data_filter)
1818
.map(|data| match endpoint_metrics(data) {

src/server/routes/ui/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ pub fn routes(
2929
) -> impl Filter<Extract = (Response<Body>,), Error = Rejection> + Clone {
3030
let data_filter = warp::any().map(move || data.clone());
3131

32-
let queue = warp::get2()
32+
let queue = warp::get()
3333
.and(warp::path::end())
3434
.and(data_filter.clone())
3535
.map(experiments::endpoint_queue);
3636

37-
let experiment = warp::get2()
37+
let experiment = warp::get()
3838
.and(warp::path("ex"))
3939
.and(warp::path::param())
4040
.and(warp::path::end())
4141
.and(data_filter.clone())
4242
.map(experiments::endpoint_experiment);
4343

44-
let agents = warp::get2()
44+
let agents = warp::get()
4545
.and(warp::path("agents"))
4646
.and(warp::path::end())
4747
.and(data_filter)
4848
.map(agents::endpoint_list);
4949

50-
let assets = warp::get2()
50+
let assets = warp::get()
5151
.and(warp::path("assets"))
5252
.and(warp::path::param())
5353
.and(warp::path::end())
@@ -144,18 +144,19 @@ fn handle_results(resp: Fallible<Response<Body>>) -> Response<Body> {
144144
}
145145
}
146146

147-
fn handle_errors(err: Rejection) -> Result<Response<Body>, Rejection> {
148-
match err.status() {
149-
StatusCode::NOT_FOUND | StatusCode::METHOD_NOT_ALLOWED => match error_404() {
150-
Ok(resp) => Ok(resp),
147+
async fn handle_errors(err: Rejection) -> Result<Response<Body>, Rejection> {
148+
if err.is_not_found() {
149+
match error_404() {
150+
Ok(resp) => return Ok(resp),
151151
Err(err) => {
152152
error!("failed to render 404 page!");
153153
crate::utils::report_failure(&err);
154-
Ok(error_500())
154+
return Ok(error_500());
155155
}
156-
},
157-
_ => Err(err),
156+
}
158157
}
158+
159+
Err(err)
159160
}
160161

161162
fn render_template<C: Serialize>(name: &str, context: &C) -> Fallible<Response<Body>> {

src/server/routes/webhooks/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use crate::server::github::{EventIssueComment, Issue, Repository};
66
use crate::server::messages::Message;
77
use crate::server::routes::webhooks::args::Command;
88
use crate::server::{Data, GithubData};
9-
use bytes::buf::Buf;
9+
use bytes::Bytes;
1010
use hmac::{Hmac, Mac};
1111
use http::{HeaderMap, Response, StatusCode};
1212
use hyper::Body;
1313
use std::str::FromStr;
1414
use std::sync::Arc;
15-
use warp::{self, filters::body::FullBody, Filter, Rejection};
15+
use warp::{self, Filter, Rejection};
1616

1717
fn process_webhook(
1818
payload: &[u8],
@@ -194,7 +194,7 @@ fn receive_endpoint(
194194
data: Arc<Data>,
195195
github_data: Arc<GithubData>,
196196
headers: HeaderMap,
197-
body: FullBody,
197+
body: Bytes,
198198
) -> Fallible<()> {
199199
let signature = headers
200200
.get("X-Hub-Signature")
@@ -209,27 +209,32 @@ fn receive_endpoint(
209209
.and_then(|h| h.to_str().ok())
210210
.ok_or_else(|| err_msg("missing header Host\n"))?;
211211

212-
process_webhook(body.bytes(), host, signature, event, &data, &github_data)
212+
process_webhook(&body[..], host, signature, event, &data, &github_data)
213213
}
214214

215215
pub fn routes(
216216
data: Arc<Data>,
217217
github_data: Option<Arc<GithubData>>,
218218
) -> impl Filter<Extract = (Response<Body>,), Error = Rejection> + Clone {
219219
let data_filter = warp::any().map(move || data.clone());
220-
let github_data_filter = warp::any().and_then(move || match github_data.clone() {
221-
Some(github_data) => Ok(github_data),
222-
None => Err(warp::reject::not_found()),
220+
let github_data_filter = warp::any().and_then(move || {
221+
let g = github_data.clone();
222+
async move {
223+
match g {
224+
Some(github_data) => Ok(github_data),
225+
None => Err(warp::reject::not_found()),
226+
}
227+
}
223228
});
224229

225-
warp::post2()
230+
warp::post()
226231
.and(warp::path::end())
227232
.and(data_filter)
228233
.and(github_data_filter)
229234
.and(warp::header::headers_cloned())
230-
.and(warp::body::concat())
235+
.and(warp::body::bytes())
231236
.map(
232-
|data: Arc<Data>, github_data: Arc<GithubData>, headers: HeaderMap, body: FullBody| {
237+
|data: Arc<Data>, github_data: Arc<GithubData>, headers: HeaderMap, body: Bytes| {
233238
let mut resp: Response<Body>;
234239
match receive_endpoint(data, github_data, headers, body) {
235240
Ok(()) => resp = Response::new("OK\n".into()),

0 commit comments

Comments
 (0)