mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-19 06:04:40 +01:00
simplify the match on h1 message type (#2006)
This commit is contained in:
parent
dfd9dc40ea
commit
f62a982a51
@ -510,25 +510,43 @@ where
|
|||||||
|
|
||||||
match msg {
|
match msg {
|
||||||
Message::Item(mut req) => {
|
Message::Item(mut req) => {
|
||||||
let pl = this.codec.message_type();
|
|
||||||
req.head_mut().peer_addr = *this.peer_addr;
|
req.head_mut().peer_addr = *this.peer_addr;
|
||||||
|
|
||||||
// merge on_connect_ext data into request extensions
|
// merge on_connect_ext data into request extensions
|
||||||
this.on_connect_data.merge_into(&mut req);
|
this.on_connect_data.merge_into(&mut req);
|
||||||
|
|
||||||
if pl == MessageType::Stream && this.flow.upgrade.is_some() {
|
match this.codec.message_type() {
|
||||||
this.messages.push_back(DispatcherMessage::Upgrade(req));
|
// Request is upgradable. add upgrade message and break.
|
||||||
break;
|
// everything remain in read buffer would be handed to
|
||||||
}
|
// upgraded Request.
|
||||||
if pl == MessageType::Payload || pl == MessageType::Stream {
|
MessageType::Stream if this.flow.upgrade.is_some() => {
|
||||||
let (ps, pl) = Payload::create(false);
|
this.messages
|
||||||
let (req1, _) =
|
.push_back(DispatcherMessage::Upgrade(req));
|
||||||
req.replace_payload(crate::Payload::H1(pl));
|
break;
|
||||||
req = req1;
|
}
|
||||||
*this.payload = Some(ps);
|
|
||||||
|
// Request is not upgradable.
|
||||||
|
MessageType::Payload | MessageType::Stream => {
|
||||||
|
/*
|
||||||
|
PayloadSender and Payload are smart pointers share the
|
||||||
|
same state.
|
||||||
|
PayloadSender is attached to dispatcher and used to sink
|
||||||
|
new chunked request data to state.
|
||||||
|
Payload is attached to Request and passed to Service::call
|
||||||
|
where the state can be collected and consumed.
|
||||||
|
*/
|
||||||
|
let (ps, pl) = Payload::create(false);
|
||||||
|
let (req1, _) =
|
||||||
|
req.replace_payload(crate::Payload::H1(pl));
|
||||||
|
req = req1;
|
||||||
|
*this.payload = Some(ps);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request has no payload.
|
||||||
|
MessageType::None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle request early
|
// handle request early when no future in InnerDispatcher state.
|
||||||
if this.state.is_empty() {
|
if this.state.is_empty() {
|
||||||
self.as_mut().handle_request(req, cx)?;
|
self.as_mut().handle_request(req, cx)?;
|
||||||
this = self.as_mut().project();
|
this = self.as_mut().project();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user