Open futurist opened 1 month ago
It's not supported but looks good. I'll implement it.
I also require this functionality. I need to read response content and alter specific sections of it using regular expressions
Just a discussion, does this feature related to some API changes? For example the API design of rama, it exposed the whole service layer and upstream, but that is more complex and not strait forward to use, but the Matcher System can be reused?
Yes, actually I'm going to change API fundamentally.
I don't know about rama
but I'll let users create a custom service that receives Requests and returns Responses.
I think it will not be very complex.
I've tested #40, the speed is good, but I cannot find a clue how to response from local file without actually making request out. Can you give an example to do this?
Could you take a look #45?
Can you provide an example of how to convert the res variable to text for rendering, given the following code:
let (mut res, _upgrade) = client.send_request(req).await?;
I want to replace the base with the content of the return to make modifications @hatoo
You can receive bodies in proxy and send back full body.
let server = proxy
.bind(("127.0.0.1", 3003), move |_client_addr, req| {
let client = client.clone();
async move {
let uri = req.uri().clone();
// You can modify request here
// or You can just return response anyware
let (res, _upgrade) = client.send_request(req).await?;
println!("{} -> {}", uri, res.status());
let (parts, body) = res.into_parts();
let body = body.collect().await?.to_bytes();
println!("{}", String::from_utf8_lossy(&body));
// You can modify response here
Ok::<_, http_mitm_proxy::default_client::Error>(Response::from_parts(
parts,
http_body_util::Full::new(body),
))
}
})
.await
.unwrap();
@hatoo
Hello,
I found that when I access it through a browser, the printed content is garbled, but page render is ok.
If I use curl -x http://127.0.0.1:7888 https://www.google.com.hk
the printed content is correct.
The cause has not been identified yet.
error image
right image
Solved!
When browser send request,the request headers includes content-encoding: gzip
,the response body is gzip file, cause garble。
I have a proxy rule like below:
Want to response from local file
/test/x.json
directly without any actual network request when the uri is https://example.com/x.json.Is it supported and how to do that?