-
Notifications
You must be signed in to change notification settings - Fork 170
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())))) | ||||||||||||||
| } | ||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we forward to the implementation for
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation follows ntex |
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| impl<Err: ErrorRenderer> Responder<Err> for PreEscaped<String> { | ||||||||||||||
| async fn respond_to(self, _: &HttpRequest) -> HttpResponse { | ||||||||||||||
| HttpResponse::build(StatusCode::OK) | ||||||||||||||
| .header(header::CONTENT_TYPE, "text/html; charset=utf-8") | ||||||||||||||
| .body(self.0) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[cfg(feature = "tide")] | ||||||||||||||
| mod tide_support { | ||||||||||||||
| use crate::PreEscaped; | ||||||||||||||
|
|
||||||||||||||
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
MessageBodynecessary here, given that we implementResponderdirectly?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
MessageBodyadds flexibility, allowing maud to be used anywhere the body it's accepted, not only in the Responder.