Skip to content

Commit 70f6f88

Browse files
committed
chore: cargo fmt
1 parent 4b05b70 commit 70f6f88

16 files changed

+115
-88
lines changed

src/lib/config.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@ pub enum ProgramStartError {
5252
ConfigCliError(ConfigError),
5353
InvalidArgs(Error),
5454
FromFile(FromFileError),
55-
PresetOptions {
56-
name: String,
57-
error: String
58-
},
59-
PresetNotSupported {
60-
name: String,
61-
},
55+
PresetOptions { name: String, error: String },
56+
PresetNotSupported { name: String },
6257
Presets(Vec<ProgramStartError>),
6358
Ip,
6459
BindHttp(std::io::Error),
@@ -104,15 +99,10 @@ impl std::fmt::Display for ProgramStartError {
10499
ProgramStartError::Ip => {
105100
write!(f, "could not retrieve the address for the config-server")
106101
}
107-
ProgramStartError::PresetOptions {
108-
name,
109-
error
110-
} => {
102+
ProgramStartError::PresetOptions { name, error } => {
111103
write!(f, "preset `{}` could not be parsed\nerror: {}", name, error)
112104
}
113-
ProgramStartError::PresetNotSupported {
114-
name,
115-
} => {
105+
ProgramStartError::PresetNotSupported { name } => {
116106
write!(f, "preset `{}` is not currently supported", name)
117107
}
118108
ProgramStartError::Presets(errors) => {

src/lib/options.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ impl ProgramOptions {
6969
.short("p")
7070
.long("port")
7171
.takes_value(true),
72-
).arg(
72+
)
73+
.arg(
7374
Arg::with_name("config")
7475
.short("c")
7576
.long("config")
7677
.takes_value(true),
77-
).arg(Arg::with_name("seed").long("seed").takes_value(true))
78+
)
79+
.arg(Arg::with_name("seed").long("seed").takes_value(true))
7880
.get_matches_from_safe(args);
7981
ProgramOptions::from_matches(matches)
8082
}
@@ -139,7 +141,7 @@ impl Default for ProgramOptions {
139141
port: 0,
140142
config_file: None,
141143
seed_file: None,
142-
proxy_timeout_secs: 5
144+
proxy_timeout_secs: 5,
143145
}
144146
}
145147
}
@@ -164,10 +166,11 @@ impl fmt::Display for ConfigError {
164166
),
165167
ConfigError::UrlInvalidScheme => {
166168
write!(f, "Could not retrieve the scheme from the URL")
167-
},
168-
ConfigError::TimeoutInvalid => {
169-
write!(f, "Invalid format for timeout. Please provide a number of seconds, eg: 3")
170169
}
170+
ConfigError::TimeoutInvalid => write!(
171+
f,
172+
"Invalid format for timeout. Please provide a number of seconds, eg: 3"
173+
),
171174
}
172175
}
173176
}

src/lib/preset.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use actix_web::{App, HttpRequest, HttpResponse};
33
use app_state::AppState;
44
use presets::m2::preset_m2::FutResp;
55
use rewrites::RewriteContext;
6-
use std::fmt;
76
use serde_json;
7+
use std::fmt;
88

99
pub trait Preset<T> {
1010
fn enhance(&self, app: App<T>) -> App<T>;

src/lib/presets/m2/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod handlers;
2-
pub mod preset_m2_opts;
32
pub mod preset_m2;
3+
pub mod preset_m2_opts;
44
pub mod replace_cookie_domain;
55
pub mod seed;
66
pub mod state;

src/lib/presets/m2/preset_m2.rs

+29-8
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,41 @@ impl Preset<AppState> for M2Preset {
5656
//
5757
let http_responders: Vec<ResourceDef> = vec![
5858
handlers::serve_r_js::register(self.options.require_path.clone()),
59-
("/__bs/reqs.json".to_string(), Method::GET, handlers::requests::handle),
60-
("/__bs/config.json".to_string(), Method::GET, handlers::config::handle),
61-
("/__bs/build.json".to_string(), Method::GET, handlers::build::handle),
62-
("/__bs/loaders.js".to_string(), Method::GET, handlers::loaders::handle),
63-
("/__bs/seed.json".to_string(), Method::GET, handlers::seed::handle),
59+
(
60+
"/__bs/reqs.json".to_string(),
61+
Method::GET,
62+
handlers::requests::handle,
63+
),
64+
(
65+
"/__bs/config.json".to_string(),
66+
Method::GET,
67+
handlers::config::handle,
68+
),
69+
(
70+
"/__bs/build.json".to_string(),
71+
Method::GET,
72+
handlers::build::handle,
73+
),
74+
(
75+
"/__bs/loaders.js".to_string(),
76+
Method::GET,
77+
handlers::loaders::handle,
78+
),
79+
(
80+
"/__bs/seed.json".to_string(),
81+
Method::GET,
82+
handlers::seed::handle,
83+
),
6484
];
6585

6686
//
6787
// Async Responders are needed when there's additional
6888
// work to be done in a handler.
6989
//
70-
let http_async_responders: Vec<AsyncResourceDef> = vec![
71-
handlers::config_capture::register(self.options.require_conf_path.clone())
72-
];
90+
let http_async_responders: Vec<AsyncResourceDef> =
91+
vec![handlers::config_capture::register(
92+
self.options.require_conf_path.clone(),
93+
)];
7394

7495
let app = http_responders
7596
.into_iter()

src/lib/presets/m2/state.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ use from_file::FromFile;
44

55
use presets::m2::preset_m2_opts::M2PresetOptions;
66
use rjs::bundle_config::BundleConfig;
7-
use rjs::modules::{ModuleData};
8-
use rjs::{RequireJsBuildConfig};
7+
use rjs::modules::ModuleData;
8+
use rjs::RequireJsBuildConfig;
99

10-
pub fn gather_state(
11-
req: &HttpRequest<AppState>,
12-
) -> Result<RequireJsBuildConfig, String> {
10+
pub fn gather_state(req: &HttpRequest<AppState>) -> Result<RequireJsBuildConfig, String> {
1311
let modules = &req
1412
.state()
1513
.req_log
@@ -48,7 +46,8 @@ pub fn gather_state(
4846
let mut c = client_config.paths.clone();
4947
derived_build_config.paths = RequireJsBuildConfig::strip_paths(&c);
5048

51-
let derived_build_config = derived_build_config.create_modules(&bundle_config, &filtered);
49+
let derived_build_config =
50+
derived_build_config.create_modules(&bundle_config, &filtered);
5251

5352
Ok(derived_build_config)
5453
}

src/lib/proxy_transform.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ pub fn proxy_req_setup(original_request: &HttpRequest<AppState>) -> ClientReques
9696
.map(|hdr| {
9797
let s = str::from_utf8(hdr.as_bytes()).unwrap_or("");
9898
s.to_string()
99-
}).collect::<Vec<String>>()
99+
})
100+
.collect::<Vec<String>>()
100101
.join("; ");
101102

102103
outgoing.set_header(http::header::COOKIE, joined_cookie);

src/lib/proxy_utils.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ where
4242
&proxy_response.headers(),
4343
target_domain.to_string(),
4444
req_target,
45-
).body(f(next_body)))
45+
)
46+
.body(f(next_body)))
4647
})
47-
}).responder()
48+
})
49+
.responder()
4850
}

src/lib/rewrites.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub fn replace_host(bytes: &str, context: &RewriteContext) -> String {
6161
.unwrap()
6262
.replace_all(bytes, |item: &Captures| {
6363
modify_url(item, &context).unwrap_or(String::from(""))
64-
}).to_string()
64+
})
65+
.to_string()
6566
}
6667

6768
///

src/lib/setup.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use from_file::FromFile;
66
use options::ProgramOptions;
77
use preset::Preset;
88
use preset::PresetOptions;
9-
use presets::m2::preset_m2_opts::M2PresetOptions;
109
use presets::m2::preset_m2::M2Preset;
10+
use presets::m2::preset_m2_opts::M2PresetOptions;
1111
use presets::m2::seed::SeedData;
1212
use proxy_transform::proxy_transform;
1313
use rjs::RequireJsClientConfig;
@@ -44,13 +44,12 @@ pub fn apply_presets(
4444
/// Instead we partially validate (json/yaml) the data structure,
4545
///
4646
pub fn validate_presets(program_config: &ProgramConfig) -> Result<(), ProgramStartError> {
47-
4847
//
4948
// A map of all possible validators
5049
//
51-
let preset_validators: HashMap<_, _> = vec![
52-
("m2", M2PresetOptions::validate)
53-
].into_iter().collect();
50+
let preset_validators: HashMap<_, _> = vec![("m2", M2PresetOptions::validate)]
51+
.into_iter()
52+
.collect();
5453

5554
//
5655
// collect any errors that occur from parsing all the options
@@ -62,9 +61,11 @@ pub fn validate_presets(program_config: &ProgramConfig) -> Result<(), ProgramSta
6261
.filter_map(|preset| {
6362
let name = preset.name.as_str();
6463

65-
let not_supported = || Some(ProgramStartError::PresetNotSupported {
66-
name: name.to_string(),
67-
});
64+
let not_supported = || {
65+
Some(ProgramStartError::PresetNotSupported {
66+
name: name.to_string(),
67+
})
68+
};
6869

6970
preset_validators
7071
.get(name)
@@ -74,7 +75,7 @@ pub fn validate_presets(program_config: &ProgramConfig) -> Result<(), ProgramSta
7475
error: e.to_string(),
7576
name: name.to_string(),
7677
}),
77-
Ok(..) => None
78+
Ok(..) => None,
7879
}
7980
})
8081
})
@@ -98,9 +99,7 @@ pub fn state_and_presets(
9899
//
99100
let mut presets_map: PresetsMap = HashMap::new();
100101

101-
let preset_factories: HashMap<_, _> = vec![
102-
("m2", M2Preset::from_value)
103-
].into_iter().collect();
102+
let preset_factories: HashMap<_, _> = vec![("m2", M2Preset::from_value)].into_iter().collect();
104103

105104
//
106105
// Loop through any presets and create an instance
@@ -118,7 +117,7 @@ pub fn state_and_presets(
118117
}
119118
_ => {
120119
unreachable!();
121-
},
120+
}
122121
}
123122
}
124123

src/lib/system.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ pub fn create(opts: ProgramOptions) -> Result<(actix::SystemRunner, String), Pro
5454
let (app_state, presets_map) = state_and_presets(&opts, &program_config, &maybe_seed);
5555
let app = App::with_state(app_state);
5656
apply_presets(app, &program_config, &presets_map)
57-
}).workers(1);
57+
})
58+
.workers(1);
5859

5960
//
6061
// Bind on either http or https depending on the

src/lib/test_utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ where
3232
let addr = srv_address.clone();
3333
let s = AppState::new(addr.clone(), "http");
3434
s
35-
}).start(handler);
35+
})
36+
.start(handler);
3637

3738
let p_addr = p.addr().to_string();
3839
(p, p_addr)

src/lib/with_body.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,31 @@ pub fn forward_request_with_body(
1919
let state = incoming_request.state();
2020
let timeout: u64 = state.opts.proxy_timeout_secs.into();
2121
let next_target = incoming_request.state().opts.target.clone();
22-
let output = incoming_request.body().from_err().and_then(move |incoming_body| {
23-
outgoing
24-
.body(incoming_body)
25-
.unwrap()
26-
.send()
27-
.timeout(Duration::from_secs(timeout))
28-
.map_err(Error::from)
29-
.and_then(move |proxy_response| {
30-
proxy_response
31-
.body()
32-
.from_err()
33-
.and_then(move |proxy_response_body| {
34-
Ok(create_outgoing(
35-
&proxy_response.status(),
36-
&proxy_response.headers(),
37-
next_target.to_string(),
38-
req_target,
39-
).body(proxy_response_body))
40-
})
41-
})
42-
});
22+
let output = incoming_request
23+
.body()
24+
.from_err()
25+
.and_then(move |incoming_body| {
26+
outgoing
27+
.body(incoming_body)
28+
.unwrap()
29+
.send()
30+
.timeout(Duration::from_secs(timeout))
31+
.map_err(Error::from)
32+
.and_then(move |proxy_response| {
33+
proxy_response
34+
.body()
35+
.from_err()
36+
.and_then(move |proxy_response_body| {
37+
Ok(create_outgoing(
38+
&proxy_response.status(),
39+
&proxy_response.headers(),
40+
next_target.to_string(),
41+
req_target,
42+
)
43+
.body(proxy_response_body))
44+
})
45+
})
46+
});
4347

4448
Box::new(output)
4549
}

src/lib/without_body.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use actix_web::{AsyncResponder, Body, Error, HttpMessage, HttpRequest, HttpRespo
66
use futures::future::{ok, Either};
77
use futures::{Future, Stream};
88

9-
use std::time::Duration;
109
use app_state::AppState;
1110
use preset::RewriteFns;
1211
use proxy_transform::create_outgoing;
1312
use proxy_transform::get_host_port;
1413
use replacer::{Replacer, Subject};
1514
use rewrites::{replace_host, RewriteContext};
15+
use std::time::Duration;
1616

1717
///
1818
/// Process regular GET requests where we don't need to consider
@@ -65,7 +65,8 @@ pub fn forward_request_without_body(
6565
target_domain,
6666
))
6767
}
68-
}).responder()
68+
})
69+
.responder()
6970
}
7071

7172
/// Pass-through response
@@ -79,7 +80,8 @@ fn pass_through_response(
7980
&proxy_response.headers(),
8081
target_domain.to_string(),
8182
req_target,
82-
).body(Body::Streaming(Box::new(
83+
)
84+
.body(Body::Streaming(Box::new(
8385
proxy_response.payload().from_err(),
8486
))));
8587

@@ -125,7 +127,8 @@ fn response_from_rewrite(
125127
&proxy_response.headers(),
126128
target_domain.to_string(),
127129
req_target,
128-
).body(next_body))
130+
)
131+
.body(next_body))
129132
});
130133

131134
Box::new(output)

0 commit comments

Comments
 (0)