Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you modify http request headers in a Safari extension?

I can do this in FF and IE, and I know it doesn't exist in Chrome yet. Anybody know if you can do this in a Safari plugin? I can't find anything that says one way or another in the documentation.

like image 743
Adam Avatar asked Jun 14 '11 22:06

Adam


People also ask

How do I view HTTP headers in Safari?

Turn on the "Develop" menu in Safari Preferences, then choose "Show Web Inspector" from the "Develop" menu. Click "Resources". Select the resource you want to inquire about and click "Headers". Thanks for that.

Can Request header be modified?

You cannot modify or remove HTTP request headers whose name starts with x-cf- or cf- except for the cf-connecting-ip HTTP request header, which you can remove. You cannot modify the value of any header commonly used to identify the website visitor's IP address, such as x-forwarded-for , true-client-ip , or x-real-ip .

Can I add custom header to HTTP request?

In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.


2 Answers

Safari has added extension support but its APIs don't let you have granular level control over Request & Response as compared to Chrome/Firefox/Edge.

To have granular level control over your Request and Response, you need setup a system wide proxy instead. Requestly Desktop App automatically does this for you and on top of that, you can do various types of modifications too like:

  • Modify Request/Response Headers
  • Redirect URLs
  • Modify Response
  • Delay Network request
  • Insert Custom Scripts
  • Change User-Agent

Here's an article about header modification using requestly https://requestly.io/feature/modify-request-response-headers/

Disclaimer: I work at Requestly

like image 166
Sahil Gupta Avatar answered Sep 20 '22 17:09

Sahil Gupta


Edit (November 2021): as pointed out in the comments, ParosProxy seems to no longer exist (and was last released ~2006 from what I can see). There are more modern options for debugging on Mac (outside of browser plugins on non-Safari browsers) like Proxyman. Rather than adding another list of links that might expire, I'll instead advise people to search for "debugging proxy" on their platform of choice instead.

Original Answer (2012):

The Safari "Develop" menu in advanced preferences allows you to partially customize headers (like the user agent), but it is quite limited.

However, if a particular browser or app does not allow you to alter the headers, just take it out of the equation. You can use things like Fiddler or ParosProxy (and many others) to alter the requests regardless of the application sending the request.

They also have the advantage of allowing you to make sure that you are sending the same headers regardless of the application in question and (depending on your requirements) potentially work across multiple browsers and apps without modification.

like image 20
Adam Comerford Avatar answered Sep 19 '22 17:09

Adam Comerford