Comments (8)
Me too.
I'm using it contact,And Chinese is not displayed
It should be a coding problem. Where to set the coding
from examples.
It should be a coding problem. Where to set the coding
Sorry, I know English isn't your first, but did you mean the Encoding?
I don't get those characters that you get in the response. Have you got anything else?
from examples.
I have the same problem as you,Coding is another problem。Thank you for your reply
from examples.
Using this complete example I am not able to re-produce a panic. Please paste full code reproduction and command snippets.
$ curl -i http://localhost:8080 --data '{"hello":"world"}'
HTTP/1.1 200 OK
content-length: 0
content-type: text/plain; charset=utf-8
date: Sun, 11 Sep 2022 15:53:17 GMT
use std::{
future::{ready, Ready},
rc::Rc,
};
use actix_web::{
dev::{self, Service, ServiceRequest, ServiceResponse, Transform},
post,
web::{self, BytesMut},
App, Error, HttpMessage, HttpServer, Responder,
};
use futures_util::{future::LocalBoxFuture, StreamExt as _};
// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
// next service in chain as parameter.
// 2. Middleware's call method gets called with normal request.
pub struct BodyLogger;
// Middleware factory is `Transform` trait from actix-service crate
// `S` - type of the next service
// `B` - type of response's body
impl<S: 'static, B> Transform<S, ServiceRequest> for BodyLogger
where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
{
type Response = ServiceResponse<B>;
type Error = Error;
type InitError = ();
type Transform = BodyLoggerMiddleware<S>;
type Future = Ready<Result<Self::Transform, Self::InitError>>;
fn new_transform(&self, service: S) -> Self::Future {
ready(Ok(BodyLoggerMiddleware {
service: Rc::new(service),
}))
}
}
pub struct BodyLoggerMiddleware<S> {
service: Rc<S>,
}
impl<S, B> Service<ServiceRequest> for BodyLoggerMiddleware<S>
where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: 'static,
{
type Response = ServiceResponse<B>;
type Error = Error;
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
dev::forward_ready!(service);
fn call(&self, mut req: ServiceRequest) -> Self::Future {
let svc = self.service.clone();
Box::pin(async move {
let mut body = BytesMut::new();
let mut stream = req.take_payload();
while let Some(chunk) = stream.next().await {
body.extend_from_slice(&chunk?);
}
println!("request body: {body:?}");
let res = svc.call(req).await?;
println!("response: {:?}", res.headers());
Ok(res)
})
}
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.wrap(BodyLogger)
.route("/", web::to(|body: String| async move { body }))
})
.bind(("127.0.0.1", 8080))?
.workers(1)
.run()
.await
}
from examples.
will re-open if reproduction is confirmed
from examples.
If I comment out these three lines, the program can be accessed normally.
If I add these three lines, the program has problems and cannot be injected into the control layer
from examples.
@15249687908 that's not a panic, if you think this is a legitimate problem, please open a new issue with full minimal example of problem
from examples.
ok
from examples.
Related Issues (20)
- Streaming responses (from an AsyncWrite) HOT 3
- About protobuf HOT 1
- actix_cors is always returing 404 on OPTIONS requests
- identity logout does not have effect
- The basic/todo app breaks with 405 (method not allowed) after create/update action applied on an item
- Please add rate-limit example HOT 2
- auth/simple-auth-server panics when default `SECRET_KEY` is used to instantiate a `actix_web::cookie::Key` instance
- Executing send_message from Actix Websocket Chat example HOT 1
- example for Mysql client library (MySql database driver) HOT 1
- No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. HOT 1
- Please add caching example HOT 4
- Expand postgres example to include querying/fetching all HOT 3
- webauthn passkey example
- Server-sent-events example not working correctly
- Having examples use actix_web_lab is confusing HOT 2
- please update rustls example to 0.22.0 HOT 2
- Improve Test Documentation
- Tagging clients in SSE
- protobuf example is not good enough!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from examples.