-
Notifications
You must be signed in to change notification settings - Fork 164
Add support for Ntex #482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for Ntex #482
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -343,6 +343,51 @@ mod actix_support { | |||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
#[cfg(feature = "ntex")] | ||||||||||||||
mod ntex_support { | ||||||||||||||
use core::{ | ||||||||||||||
error::Error, | ||||||||||||||
mem, | ||||||||||||||
task::{Context, Poll}, | ||||||||||||||
}; | ||||||||||||||
use ntex::{ | ||||||||||||||
http::{ | ||||||||||||||
body::{BodySize, MessageBody}, | ||||||||||||||
header, StatusCode, | ||||||||||||||
}, | ||||||||||||||
util::Bytes, | ||||||||||||||
web::{ErrorRenderer, HttpRequest, HttpResponse, Responder}, | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
use crate::PreEscaped; | ||||||||||||||
use alloc::{rc::Rc, string::String}; | ||||||||||||||
|
||||||||||||||
impl MessageBody for PreEscaped<String> { | ||||||||||||||
fn size(&self) -> BodySize { | ||||||||||||||
self.0.size() | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
fn poll_next_chunk( | ||||||||||||||
&mut self, | ||||||||||||||
_: &mut Context<'_>, | ||||||||||||||
) -> Poll<Option<Result<Bytes, Rc<dyn Error>>>> { | ||||||||||||||
if self.0.is_empty() { | ||||||||||||||
Poll::Ready(None) | ||||||||||||||
} else { | ||||||||||||||
Poll::Ready(Some(Ok(Bytes::from(mem::take(&mut self.0).into_bytes())))) | ||||||||||||||
} | ||||||||||||||
|
if self.0.is_empty() { | |
Poll::Ready(None) | |
} else { | |
Poll::Ready(Some(Ok(Bytes::from(mem::take(&mut self.0).into_bytes())))) | |
} | |
self.0.poll_next_chunk(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation follows ntex impl MessageBody for String
, avoiding unnecessary allocations and one-shot consumption of the body, performance wise it's the best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is implementing
MessageBody
necessary here, given that we implementResponder
directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
MessageBody
adds flexibility, allowing maud to be used anywhere the body it's accepted, not only in the Responder.