我想为 OAuth 目的获取 Authorization Bearer 标头,但是阅读文档看起来有点混乱
use nickel::{Nickel, JsonBody, HttpRouter, Request, Response, MiddlewareResult, MediaType};
// Get the full Authorization header from the incoming request headers
let auth_header = match request.origin.headers.get::<Authorization<Bearer>>() {
Some(header) => header,
None => panic!("No authorization header found")
};
这会产生错误:
src/main.rs:84:56: 84:86 错误:
hyper::header::HeaderFormat
没有为类型hyper::header::common::authorization::Authorization<hyper::header::common::authorization::Bearer>
[E0277]实现特征
从实现来看,我似乎是正确的:
https://github.com/hyperium/hyper/blob/master/src/header/common/authorization.rs
impl<S: Scheme + Any> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(scheme) = <S as Scheme>::scheme() {
try!(write!(f, "{} ", scheme))
};
self.0.fmt_scheme(f)
}
}