Skip to content

Commit 906cc2c

Browse files
committed
chore: adapt to new woothee/tungstenite
kill a now unused argument to register Closes #110
1 parent eaaccc0 commit 906cc2c

7 files changed

Lines changed: 18 additions & 29 deletions

File tree

autopush-common/src/db/commands.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use cadence::{Counted, StatsdClient};
88
use chrono::Utc;
99
use futures::{future, Future};
1010
use futures_backoff::retry_if;
11+
use rusoto_core::RusotoError;
1112
use rusoto_dynamodb::{
1213
AttributeValue, BatchWriteItemError, DeleteItemError, DeleteItemInput, DeleteItemOutput,
1314
DynamoDb, GetItemError, GetItemInput, GetItemOutput, ListTablesInput, ListTablesOutput,
@@ -25,11 +26,10 @@ use crate::util::timing::sec_since_epoch;
2526

2627
macro_rules! retryable_error {
2728
($name:ident, $type:ty, $property:ident) => {
28-
pub fn $name(err: &$type) -> bool {
29+
pub fn $name(err: &RusotoError<$type>) -> bool {
2930
match err {
30-
$property::InternalServerError(_) | $property::ProvisionedThroughputExceeded(_) => {
31-
true
32-
}
31+
RusotoError::Service($property::InternalServerError(_))
32+
| RusotoError::Service($property::ProvisionedThroughputExceeded(_)) => true,
3333
_ => false,
3434
}
3535
}

autopush-common/src/db/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ impl DynamoStorage {
200200
channel_id: &Uuid,
201201
message_month: &str,
202202
endpoint: &str,
203-
key: Option<String>,
204203
) -> MyFuture<RegisterResponse> {
205204
let ddb = self.ddb.clone();
206205
let mut chids = HashSet::new();

autopush/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ tokio-service = "0.1.0"
5353
tokio-tungstenite = { version = "0.8.0", default-features = false }
5454
tungstenite = { version = "0.8.1", default-features = false }
5555
uuid = { version = "0.7.4", features = ["serde", "v4"] }
56-
# XXX: pin woothee until >= 0.8.1
5756
woothee = "0.10.0"

autopush/src/client.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::rc::Rc;
1818
use std::time::Duration;
1919
use tokio_core::reactor::Timeout;
2020
use uuid::Uuid;
21-
use woothee::parser::Parser;
2221

2322
use autopush_common::db::{CheckStorageResponse, HelloResponse, RegisterResponse};
2423
use autopush_common::errors::*;
@@ -489,8 +488,7 @@ where
489488
}
490489
let now = ms_since_epoch();
491490
let elapsed = (now - webpush.connected_at) / 1_000;
492-
let parser = Parser::new();
493-
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&parser, &user_agent);
491+
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&user_agent);
494492
// dogstatsd doesn't support timers: use histogram instead
495493
srv.metrics
496494
.time_with_tags("ua.connection.lifespan", elapsed)
@@ -553,7 +551,7 @@ where
553551
"connection_type" => &stats.connection_type,
554552
"ua_name" => ua_result.name,
555553
"ua_os_family" => metrics_os,
556-
"ua_os_ver" => ua_result.os_version,
554+
"ua_os_ver" => ua_result.os_version.into_owned(),
557555
"ua_browser_family" => metrics_browser,
558556
"ua_browser_ver" => ua_result.version,
559557
"ua_category" => ua_result.category,
@@ -863,7 +861,7 @@ where
863861
Ok(endpoint) => {
864862
data.srv
865863
.ddb
866-
.register(&uaid, &channel_id, &message_month, &endpoint, key)
864+
.register(&uaid, &channel_id, &message_month, &endpoint)
867865
}
868866
Err(_) => Box::new(future::ok(RegisterResponse::Error {
869867
error_msg: "Failed to generate endpoint".to_string(),

autopush/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#[macro_use]
21
extern crate slog;
32
#[macro_use]
43
extern crate slog_scope;

autopush/src/server/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tokio_core::reactor::{Core, Handle, Timeout};
3030
use tokio_io;
3131
use tokio_tungstenite::{accept_hdr_async, WebSocketStream};
3232
use tungstenite::handshake::server::Request;
33-
use tungstenite::Message;
33+
use tungstenite::{self, Message};
3434
use uuid::Uuid;
3535

3636
use autopush_common::db::DynamoStorage;
@@ -919,6 +919,8 @@ where
919919
self.ws_pong_timeout = false;
920920
task::current().notify();
921921
}
922+
923+
Message::Close(_) => return Err(tungstenite::Error::ConnectionClosed.into()),
922924
}
923925
}
924926
}

autopush/src/user_agent.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ const VALID_UA_BROWSER: &[&str] = &["Chrome", "Firefox", "Safari", "Opera"];
1111
// field). Windows has many values and we only care that its Windows
1212
const VALID_UA_OS: &[&str] = &["Firefox OS", "Linux", "Mac OSX"];
1313

14-
pub fn parse_user_agent<'a>(
15-
parser: &'a Parser,
16-
agent: &str,
17-
) -> (WootheeResult<'a>, &'a str, &'a str) {
14+
pub fn parse_user_agent(agent: &str) -> (WootheeResult, &str, &str) {
15+
let parser = Parser::new();
1816
let wresult = parser.parse(&agent).unwrap_or_else(|| WootheeResult {
1917
name: "",
2018
category: "",
2119
os: "",
22-
os_version: "".to_string(),
20+
os_version: "".into(),
2321
browser_type: "",
24-
version: "".to_string(),
22+
version: "",
2523
vendor: "",
2624
});
2725

@@ -43,15 +41,12 @@ pub fn parse_user_agent<'a>(
4341

4442
#[cfg(test)]
4543
mod tests {
46-
use woothee::parser::Parser;
47-
4844
use super::parse_user_agent;
4945

5046
#[test]
5147
fn test_linux() {
5248
let agent = r#"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/20090807 Mandriva Linux/1.9.1.2-1.1mud2009.1 (2009.1) Firefox/3.5.2 FirePHP/0.3,gzip(gfe),gzip(gfe)"#;
53-
let parser = Parser::new();
54-
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&parser, &agent);
49+
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&agent);
5550
assert_eq!(metrics_os, "Linux");
5651
assert_eq!(ua_result.os, "Linux");
5752
assert_eq!(metrics_browser, "Firefox");
@@ -60,8 +55,7 @@ mod tests {
6055
#[test]
6156
fn test_windows() {
6257
let agent = r#"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)"#;
63-
let parser = Parser::new();
64-
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&parser, &agent);
58+
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&agent);
6559
assert_eq!(metrics_os, "Windows");
6660
assert_eq!(ua_result.os, "Windows 7");
6761
assert_eq!(metrics_browser, "Firefox");
@@ -71,8 +65,7 @@ mod tests {
7165
fn test_osx() {
7266
let agent =
7367
r#"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:2.1.1) Gecko/ Firefox/5.0.1"#;
74-
let parser = Parser::new();
75-
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&parser, &agent);
68+
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&agent);
7669
assert_eq!(metrics_os, "Mac OSX");
7770
assert_eq!(ua_result.os, "Mac OSX");
7871
assert_eq!(metrics_browser, "Firefox");
@@ -82,8 +75,7 @@ mod tests {
8275
fn test_other() {
8376
let agent =
8477
r#"BlackBerry9000/4.6.0.167 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/102"#;
85-
let parser = Parser::new();
86-
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&parser, &agent);
78+
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&agent);
8779
assert_eq!(metrics_os, "Other");
8880
assert_eq!(ua_result.os, "BlackBerry");
8981
assert_eq!(metrics_browser, "Other");

0 commit comments

Comments
 (0)