vocaliu / chrome-redirector

Automatically exported from code.google.com/p/chrome-redirector
GNU General Public License v3.0
0 stars 0 forks source link

[RULE] Replace "Content-Type" response header: image/x-png -> image/png #21

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Chrome does not recognise MIME type image/x-png as a PNG image, but downloads 
the file as a binary because the canonical MIME type is image/png. Some servers 
send the old type, though. How can I use your tool to globally replace this 
content type (in response headers only!) so as to make Chrome display such 
images correctly using the internal viewer (not any plugin like Quicktime which 
might be installed or not)?

Original issue reported on code.google.com by alexande...@googlemail.com on 26 Aug 2012 at 1:19

GoogleCodeExporter commented 9 years ago
I'm not sure if it works, but you can try modifying the value of `Content-Type' 
response header to `image/png'. You may need to specify both URL pattern and 
resource type (find it out with built-in debugger) to do a exact match.

Original comment by CyrilF...@gmail.com on 26 Aug 2012 at 1:31

GoogleCodeExporter commented 9 years ago
Under "substitution" there is "Response Header" in the drop-down list, but it 
does not seem to have an effect. The URL is matched, but no response headers 
are changed. Can you please test this yourself and see if there is any bug? The 
manual shows no examples for this case and is not very comprehensive all in all.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 11:06

Attachments:

GoogleCodeExporter commented 9 years ago
It would be helpful if you uploaded the exported rule

Original comment by cws.de...@gmail.com on 2 Sep 2012 at 11:11

GoogleCodeExporter commented 9 years ago
Is it really that hard to type the few characters from my screenshot? I have no 
idea how to export a rule, this is why I created the screenshot in the first 
place.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 11:42

GoogleCodeExporter commented 9 years ago
Oh BTW, I am using a little Java HTTP server 
(http://elonen.iki.fi/code/nanohttpd/#download) in order to test everything. 
You can just change the MIME type of PNG to image/x-png in the source code (the 
whole server is just one file), fire it up, copy one PNG file into the web root 
directory and test. The PNG file will be downloaded, not displayed. If the rule 
would work, the image would be shown.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 11:49

GoogleCodeExporter commented 9 years ago
Yes, at least I cannot see the content of `content filter'; You may 
alternatively describe that. It would be better if you upload debug result.

Original comment by cws.de...@gmail.com on 2 Sep 2012 at 11:50

GoogleCodeExporter commented 9 years ago
Content Filter is set to "all", i.e. the filter is applied to all content.

Now the filter works! I have not changed it, just deactivated the extension and 
reactivated it again. The debugger shows it works and the practical web site 
test too. How weird is that? Can it be an issue with the cache? With the 
extension itself?

Anyway, thanks. And for the record, I have found out how to export rules and 
debug sessions. I had not expected the buttons to be hidden behind text links, 
sorry.

A follow-up question: Is it possible to match a response content-type header 
rather than replacing it always? In my case it is not necessary, but I would 
like to know just in case.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 12:05

Attachments:

GoogleCodeExporter commented 9 years ago
Did you mean making Redirector matching by response headers rather than by 
URLs? At the moment it's not possible. I think URL patterns are efficient and 
accurate enough in most cases.

Original comment by cws.de...@gmail.com on 2 Sep 2012 at 12:16

GoogleCodeExporter commented 9 years ago
No, I mean matching the URL, but then having search & replace withing response 
headers, e.g.:

Substitution: Response Headers -> Content-Type
Search expression (wildcard or regex): x-png
Replacement: png

I currently cannot make the header replacement dependent on its content, only 
on its name. I would like to optionally do both. Typical user, never satisfied. 
;-) Anyway, as I said, for the x-png issue the current functionality is 
sufficient. :) 

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 12:32

GoogleCodeExporter commented 9 years ago
Hmm, not possible currently and won't be implemented in the near future.

Besides, your rule is not strict enough. RegExp pattern \.png$ is better.

Original comment by cws.de...@gmail.com on 2 Sep 2012 at 12:49

GoogleCodeExporter commented 9 years ago
I have updated the rule, thanks.

There is another issue: In my Chrome (version 21) on Win XP SP3 the Redirector 
icon in the URL input field vanishes on my test page http://localhost if I 
click the icon to temporarils deactivate the extension, so I cannot reactivate 
it again the same way. I need to go to the right-click context menu to 
reactivate it which is rather inconvenient.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 1:03

GoogleCodeExporter commented 9 years ago
The icon won't show up if this extension is deactivated. It's by design. BTW, 
this feature will be removed in future releases since lots of people have 
complained about it.

Original comment by cws.de...@gmail.com on 2 Sep 2012 at 1:17

GoogleCodeExporter commented 9 years ago
Well, I do like the icon. You can always make its appearance configurable, but 
please keep it. Just make sure that it is still shown, only greyed out like 
Adblock Plus, for example.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 1:47

GoogleCodeExporter commented 9 years ago
Oh, and I guess I really need a way to only replace the content type if it is 
exactly image/x-png. Look at this URL: 
http://freetz.org/attachment/ticket/1908/arris1.png.

If you use the filter on that page, it will be applied even though the page is 
text/html, not image/x-png. It leads to the page not being displayed anymore. 
But I cannot exclude object type "main frame" because then that URL works, but 
not stand-alone PNG images with image/x-png anymore. There is no way to get 
both correct.

I hope you have a solution for me. Do you?

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 3:50

GoogleCodeExporter commented 9 years ago
I think making content filter contains only `Image' will work. You may use 
debugger to verify if `image/x-png' is of type `Image'.

Original comment by cws.de...@gmail.com on 2 Sep 2012 at 3:56

GoogleCodeExporter commented 9 years ago
No, I had tested that before. Then it does not work for my test case with local 
web server sending an image via http://localhost/test.png with Content-Type 
image/x-png anymore.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 4:08

GoogleCodeExporter commented 9 years ago
Probably because in this case the PNG image is regarded as "main frame" by your 
tool. The conditions would have to be more fine-grained.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 4:09

GoogleCodeExporter commented 9 years ago
Oh, and because you asked: the debugger marks my localhost PNG URL as "@Main 
frame", as I assumed.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 4:16

GoogleCodeExporter commented 9 years ago
Resources are classified by Chrome so there's no way to change it. The only way 
I can think up here is to blacklist this type of URLs.

Original comment by cws.de...@gmail.com on 2 Sep 2012 at 4:21

GoogleCodeExporter commented 9 years ago
My feature request would also be a way...

And I can hardly imagine a URL blacklisting scheme which would blacklist all 
Trac installations in the world plus all other servers which send URLs ending 
with ".png", but correctly classified by their MIME type. For a good filter the 
URL is just not enough because the headers decide how a browser treats 
documents and resources.

Original comment by alexande...@googlemail.com on 2 Sep 2012 at 4:27

GoogleCodeExporter commented 9 years ago
No, there's no need to blacklist all possible URLs but the ones you 
encountered. In this case, you may compose the match pattern as 
^http://(?!([^/]+\.)?freetz\.org/).*\.png$ ; you may add domains foo.org and 
bar.org like this: 
^http://(?!([^/]+\.)?(freetz\.org|foo\.org|bar\.org)/).*\.png$

Original comment by cws.de...@gmail.com on 2 Sep 2012 at 4:39

GoogleCodeExporter commented 9 years ago
Okay, I got the message: You have no intention of extending your software, 
neither concerning the vanishing icon nor concerning a better way to filter 
headers. I accept that and will try to find another one which can fulfill my 
needs or maybe just fork yours, should I even feel inclined to learn extension 
programming and JS.

I do want to thank you for trying to help me, responding quickly and offering 
good advice. I really do. So thanks a lot. :-)

Original comment by alexande...@googlemail.com on 3 Sep 2012 at 8:52