Struct traq_bot_http::RequestParser
source · pub struct RequestParser { /* private fields */ }
Expand description
HTTP POSTリクエストのパーサー
Implementations§
source§impl RequestParser
impl RequestParser
sourcepub fn parse(
&self,
headers: HeaderMap,
body: &[u8]
) -> Result<Event, ParseError>
pub fn parse( &self, headers: HeaderMap, body: &[u8] ) -> Result<Event, ParseError>
HTTP POSTリクエストをパースします。
Arguments
headers
- リクエストのヘッダーbody
- リクエストのボディ
Example
use http::HeaderMap;
use traq_bot_http::{RequestParser, Event};
let headers: HeaderMap = [
("Content-Type", "application/json"),
("X-TRAQ-BOT-TOKEN", "verification_token"),
("X-TRAQ-BOT-EVENT", "PING"),
]
.into_iter()
.map(|(k, v)| (k.parse().unwrap(), v.parse().unwrap()))
.collect();
let body = br#"{"eventTime": "2019-05-07T04:50:48.582586882Z"}"#;
let verification_token = "verification_token";
let parser = RequestParser::new(verification_token);
let event = parser.parse(headers, body);
match event {
Ok(Event::Ping(_)) => (),
_ => unreachable!(),
}
Trait Implementations§
source§impl Clone for RequestParser
impl Clone for RequestParser
source§fn clone(&self) -> RequestParser
fn clone(&self) -> RequestParser
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl RefUnwindSafe for RequestParser
impl Send for RequestParser
impl Sync for RequestParser
impl Unpin for RequestParser
impl UnwindSafe for RequestParser
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more