titanium-web-proxy icon indicating copy to clipboard operation
titanium-web-proxy copied to clipboard

Can't block images

Open jiehuuu opened this issue 5 years ago • 7 comments

I'm trying to block images, however, it doesn't work

I am using BeforeResponse event

Tried this:

if (e.HttpClient.Response.ContentType.Contains("image")) {
 e.SetResponseBodyString("");
}

and this

if (e.HttpClient.Response.ContentType.Contains("image")) {
 byte[] btBody = Encoding.UTF8.GetBytes("empty");
 var response = new OkResponse(btBody);
 response.HttpVersion = e.HttpClient.Request.HttpVersion;
 e.Respond(response);
}

jiehuuu avatar May 29 '20 21:05 jiehuuu

Try this:

                if (e.HttpClient.Response.ContentType?.Contains("image") == true)
                {
                    await e.GetResponseBody();
                    e.SetResponseBodyString("");
                }

This works for me.

honfika avatar May 30 '20 07:05 honfika

Thanks for your response... but not working on my side...

https://prnt.sc/sqn99w

private async Task ProxyServer_BeforeResponse(object sender, SessionEventArgs e)
        {
            if (e.HttpClient.Response.ContentType?.Contains("image") == true)
            {
                Console.WriteLine("Image found: replacing request body");

                await e.GetResponseBody();
                e.SetResponseBodyString("");

                Console.WriteLine("Image found: body replaced to empty");
            }
}

jiehuuu avatar May 30 '20 13:05 jiehuuu

Is this BeforeResponse handler called?

honfika avatar May 30 '20 14:05 honfika

Yes, i inserted a breakpoint and hited!

can u send me ur project file?

jiehuuu avatar May 30 '20 18:05 jiehuuu

I used the Basic example from this repository.

honfika avatar May 31 '20 06:05 honfika

Hello, i tried again and worked... but some images are not blocked, like svg or base64 images

rgbcrow avatar Jun 02 '20 19:06 rgbcrow

Maybe the content type is different.

base64 image is which is embedded in the html? of course it is not blocked with this method... you have to modify html body of the http response for that. It is not trivial to block every image in the webpage, since it can be drawn for example by a javascript, too...

may i close this issue?

honfika avatar Jun 02 '20 20:06 honfika