mirror of https://github.com/fafhrd91/actix-web
Merge branch 'master' into patch-1
This commit is contained in:
commit
eaf2441622
|
@ -1,5 +1,11 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [2.0.NEXT] - 2020-01-xx
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Use `sha-1` crate instead of unmaintained `sha1` crate
|
||||||
|
|
||||||
## [2.0.0] - 2019-12-25
|
## [2.0.0] - 2019-12-25
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -74,7 +74,7 @@ rand = "0.7"
|
||||||
regex = "1.3"
|
regex = "1.3"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
sha1 = "0.6"
|
sha-1 = "0.8"
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
serde_urlencoded = "0.6.1"
|
serde_urlencoded = "0.6.1"
|
||||||
time = "0.1.42"
|
time = "0.1.42"
|
||||||
|
|
|
@ -207,12 +207,13 @@ static WS_GUID: &str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||||
|
|
||||||
// TODO: hash is always same size, we dont need String
|
// TODO: hash is always same size, we dont need String
|
||||||
pub fn hash_key(key: &[u8]) -> String {
|
pub fn hash_key(key: &[u8]) -> String {
|
||||||
|
use sha1::Digest;
|
||||||
let mut hasher = sha1::Sha1::new();
|
let mut hasher = sha1::Sha1::new();
|
||||||
|
|
||||||
hasher.update(key);
|
hasher.input(key);
|
||||||
hasher.update(WS_GUID.as_bytes());
|
hasher.input(WS_GUID.as_bytes());
|
||||||
|
|
||||||
base64::encode(&hasher.digest().bytes())
|
base64::encode(hasher.result().as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -277,6 +278,12 @@ mod test {
|
||||||
assert_eq!(format!("{}", OpCode::Bad), "BAD");
|
assert_eq!(format!("{}", OpCode::Bad), "BAD");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hash_key() {
|
||||||
|
let hash = hash_key(b"hello actix-web");
|
||||||
|
assert_eq!(&hash, "cR1dlyUUJKp0s/Bel25u5TgvC3E=");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn closecode_from_u16() {
|
fn closecode_from_u16() {
|
||||||
assert_eq!(CloseCode::from(1000u16), CloseCode::Normal);
|
assert_eq!(CloseCode::from(1000u16), CloseCode::Normal);
|
||||||
|
|
|
@ -206,8 +206,14 @@ impl HttpRequest {
|
||||||
&self.0.config
|
&self.0.config
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an application data stored with `App::extension()` method during
|
/// Get an application data object stored with `App::data` or `App::app_data`
|
||||||
/// application configuration.
|
/// methods during application configuration.
|
||||||
|
///
|
||||||
|
/// If `App::data` was used to store object, use `Data<T>`:
|
||||||
|
///
|
||||||
|
/// ```rust,ignore
|
||||||
|
/// let opt_t = req.app_data::<Data<T>>();
|
||||||
|
/// ```
|
||||||
pub fn app_data<T: 'static>(&self) -> Option<&T> {
|
pub fn app_data<T: 'static>(&self) -> Option<&T> {
|
||||||
if let Some(st) = self.0.app_data.get::<T>() {
|
if let Some(st) = self.0.app_data.get::<T>() {
|
||||||
Some(&st)
|
Some(&st)
|
||||||
|
|
Loading…
Reference in New Issue