mirror of https://github.com/rwf2/Rocket.git
Change the type for port to u16 in config.
This commit is contained in:
parent
44296980fc
commit
a6084ab3e2
|
@ -15,7 +15,7 @@ pub struct Config {
|
||||||
/// The address to serve on.
|
/// The address to serve on.
|
||||||
pub address: String,
|
pub address: String,
|
||||||
/// The port to serve on.
|
/// The port to serve on.
|
||||||
pub port: usize,
|
pub port: u16,
|
||||||
/// How much information to log.
|
/// How much information to log.
|
||||||
pub log_level: LoggingLevel,
|
pub log_level: LoggingLevel,
|
||||||
/// The environment that this configuration corresponds to.
|
/// The environment that this configuration corresponds to.
|
||||||
|
@ -99,7 +99,7 @@ impl Config {
|
||||||
/// returned:
|
/// returned:
|
||||||
///
|
///
|
||||||
/// * **address**: String
|
/// * **address**: String
|
||||||
/// * **port**: Integer
|
/// * **port**: Integer (16-bit unsigned)
|
||||||
/// * **session_key**: String (192-bit base64)
|
/// * **session_key**: String (192-bit base64)
|
||||||
/// * **log**: String
|
/// * **log**: String
|
||||||
///
|
///
|
||||||
|
@ -119,7 +119,11 @@ impl Config {
|
||||||
return Err(self.bad_type(name, val, "an unsigned integer"));
|
return Err(self.bad_type(name, val, "an unsigned integer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.port = port as usize;
|
if port > (u16::max_value() as i64) {
|
||||||
|
return Err(self.bad_type(name, val, "a 16-bit unsigned integer"))
|
||||||
|
}
|
||||||
|
|
||||||
|
self.port = port as u16;
|
||||||
} else if name == "session_key" {
|
} else if name == "session_key" {
|
||||||
let key = parse!(self, name, val, as_str, "a string")?;
|
let key = parse!(self, name, val, as_str, "a string")?;
|
||||||
if key.len() != 32 {
|
if key.len() != 32 {
|
||||||
|
@ -231,7 +235,7 @@ impl Config {
|
||||||
|
|
||||||
/// Sets the `port` in `self` to `var` and returns the structure.
|
/// Sets the `port` in `self` to `var` and returns the structure.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn port(mut self, var: usize) -> Self {
|
pub fn port(mut self, var: u16) -> Self {
|
||||||
self.port = var;
|
self.port = var;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -284,4 +288,3 @@ impl PartialEq for Config {
|
||||||
&& self.filepath == other.filepath
|
&& self.filepath == other.filepath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -567,6 +567,13 @@ mod test {
|
||||||
"#.to_string(), TEST_CONFIG_FILENAME), {
|
"#.to_string(), TEST_CONFIG_FILENAME), {
|
||||||
default_config(Staging).port(6000)
|
default_config(Staging).port(6000)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
check_config!(RocketConfig::parse(r#"
|
||||||
|
[stage]
|
||||||
|
port = 65535
|
||||||
|
"#.to_string(), TEST_CONFIG_FILENAME), {
|
||||||
|
default_config(Staging).port(65535)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -589,6 +596,16 @@ mod test {
|
||||||
[staging]
|
[staging]
|
||||||
port = -1
|
port = -1
|
||||||
"#.to_string(), TEST_CONFIG_FILENAME).is_err());
|
"#.to_string(), TEST_CONFIG_FILENAME).is_err());
|
||||||
|
|
||||||
|
assert!(RocketConfig::parse(r#"
|
||||||
|
[staging]
|
||||||
|
port = 65536
|
||||||
|
"#.to_string(), TEST_CONFIG_FILENAME).is_err());
|
||||||
|
|
||||||
|
assert!(RocketConfig::parse(r#"
|
||||||
|
[staging]
|
||||||
|
port = 105836
|
||||||
|
"#.to_string(), TEST_CONFIG_FILENAME).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -25,7 +25,7 @@ use http::uri::URI;
|
||||||
/// application.
|
/// application.
|
||||||
pub struct Rocket {
|
pub struct Rocket {
|
||||||
address: String,
|
address: String,
|
||||||
port: usize,
|
port: u16,
|
||||||
router: Router,
|
router: Router,
|
||||||
default_catchers: HashMap<u16, Catcher>,
|
default_catchers: HashMap<u16, Catcher>,
|
||||||
catchers: HashMap<u16, Catcher>,
|
catchers: HashMap<u16, Catcher>,
|
||||||
|
|
Loading…
Reference in New Issue