Comments (2)
Does this error happen on all downloads, or only on a specific download?
from hudsucker.
async fn handle_response(&mut self, _ctx: &HttpContext, mut res: Response<Body>) -> Response<Body> {
res = decode_response(res).unwrap();
let req = match self.req().clone() {
Some(req) => req,
None => return res,
};
let content_type_str: String = res
.headers()
.get(CONTENT_TYPE)
.and_then(|ct| ct.to_str().ok())
.unwrap_or_default()
.to_owned();
// 是否是文本类型
let is_text_content = ["text/", "application/json", "application/javascript", "application/xml"]
.iter()
.any(|&typ| content_type_str.contains(typ));
if is_text_content {
let uri_str = remove_default_port(&Url::parse(format!("{}", req.uri()).as_str()).expect("Url parse error"));
let rule = find_rule(&uri_str, MapType::Local);
// 判断 effect_tools 中是否有 fun_debug
let web_tools = WEB_TOOL_VEC.lock().unwrap().clone();
let need_effect_tools = content_type_str.contains("text/html") && web_tools.len() > 0;
if need_effect_tools || rule.is_some() {
let body_mut = res.body_mut();
let body_bytes = body_mut.collect().await.unwrap_or_default().to_bytes();
// gzip 需要通过flate2库Decode内容
let mut body_string = String::from_utf8_lossy(&body_bytes).to_string();
if let Some(rule) = rule {
let local_content = rule.local_content;
body_string = local_content.unwrap_or(body_string);
}
if need_effect_tools {
// 添加fun-console脚本
body_string += web_tools.join("\n").as_str();
}
*body_mut = Body::from(body_string.clone());
// 删除 content-encoding
res.headers_mut().remove(CONTENT_ENCODING);
// 判断是否有content-length,有的话需要计算长度
if res.headers().get(CONTENT_LENGTH).is_some() {
let content_length = HeaderValue::from(body_string.len());
res.headers_mut().insert(CONTENT_LENGTH, content_length);
}
}
// 读取新的 body 传给前端
let body_mut = res.body_mut();
let body_bytes = body_mut.collect().await.unwrap_or_default().to_bytes();
*body_mut = Body::from(Full::new(body_bytes.clone()));
let output_response = ProxiedResponse::new(
res.status(),
res.version(),
res.headers().clone(),
body_bytes,
chrono::Local::now().timestamp_nanos_opt().unwrap(),
hosts::get_ip(req.uri().host().unwrap()),
);
self.set_res(output_response).send_output();
} else {
let output_response = ProxiedResponse::new(
res.status(),
res.version(),
res.headers().clone(),
Bytes::new(),
chrono::Local::now().timestamp_nanos_opt().unwrap(),
hosts::get_ip(req.uri().host().unwrap()),
);
self.set_res(output_response).send_output();
}
res
}
I know why . This handle_response deal with all the reponse and downloads bytes is big. so body_mut.collect().await.unwrap_or_default().to_bytes();
this code will wait long time .
I now change the handle_response just deal text content type.
from hudsucker.
Related Issues (20)
- Access to the open websockets HOT 3
- transfer-encoding:chunked HOT 4
- Cargo bech does not build HOT 1
- How to obtain the request URI address in `HttpHandler::handle_response`? HOT 1
- Handle Specific Response? HOT 1
- Failed to establish TLS connection: HOT 2
- How to get the original data of Response body? HOT 2
- Cargo audit failure due to tungstenite dependency HOT 3
- Failed to forward request: client requires absolute-form URIs HOT 13
- How to serliaize hudsucker::Body to bytes? HOT 2
- `WebSocketContext` is wrong in `WebSocketHandler` HOT 2
- WebSocket TLS not support ? HOT 5
- How to set whitelist url not proxy by hudsucker ? HOT 10
- Seems not work with Proxifier HOT 4
- I found that "text/event-stream;" type not send one by one, It send when all the content down HOT 5
- [feature request]: Allow proxy to untrusted SSL certificate websites. HOT 1
- How to parse Proxy-Authorization in HTTPS requests ? HOT 3
- SSL HOT 6
- accessing local website prompt: certificate(net::ERR_CERT_COMMON_NAME_INVALID). and page display: HTTP ERROR 502 HOT 10
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 hudsucker.