-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into sg-test-pagerduty
- Loading branch information
Showing
69 changed files
with
8,603 additions
and
1,236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP INDEX index_crates_name_ordering; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE INDEX index_crates_name_ordering ON crates (name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
We require that all requests include a `User-Agent` header. To allow us to determine the impact your bot has on our service, we ask that your user agent actually identify your bot, and not just report the HTTP client library you're using. Including contact information will also reduce the chance that we will need to take action against your bot. | ||
|
||
Bad: | ||
User-Agent: reqwest/0.9.1 | ||
|
||
Better: | ||
User-Agent: my_crawler | ||
|
||
Best: | ||
User-Agent: my_crawler (my_crawler.com/info) | ||
User-Agent: my_crawler (help@my_crawler.com) | ||
|
||
If you believe you've received this message in error, please email help@crates.io and include the request id {}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! Middleware that blocks requests with no user-agent header | ||
|
||
use super::prelude::*; | ||
|
||
use std::collections::HashMap; | ||
use std::io::Cursor; | ||
use util::request_header; | ||
|
||
// Can't derive debug because of Handler. | ||
#[allow(missing_debug_implementations)] | ||
#[derive(Default)] | ||
pub struct RequireUserAgent { | ||
handler: Option<Box<dyn Handler>>, | ||
} | ||
|
||
impl AroundMiddleware for RequireUserAgent { | ||
fn with_handler(&mut self, handler: Box<dyn Handler>) { | ||
self.handler = Some(handler); | ||
} | ||
} | ||
|
||
impl Handler for RequireUserAgent { | ||
fn call(&self, req: &mut dyn Request) -> Result<Response, Box<dyn Error + Send>> { | ||
let has_user_agent = request_header(req, "User-Agent") != ""; | ||
if !has_user_agent { | ||
let body = format!( | ||
include_str!("no_user_agent_message.txt"), | ||
request_header(req, "X-Request-Id"), | ||
); | ||
let mut headers = HashMap::new(); | ||
headers.insert("Content-Length".to_string(), vec![body.len().to_string()]); | ||
Ok(Response { | ||
status: (403, "Forbidden"), | ||
headers, | ||
body: Box::new(Cursor::new(body.into_bytes())), | ||
}) | ||
} else { | ||
self.handler.as_ref().unwrap().call(req) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.