New Safari extension: ChangeTheHeaders to customize HTTP request headers

New Safari extension: ChangeTheHeaders to customize HTTP request headers



New Safari extension: ChangeTheHeaders to customize HTTP request headers

March 27, 2025
By Jeff Johnson of Underpass App Company

I’m happy to announce that I’ve just released a new app! ChangeTheHeaders is a Safari extension for iOS, iPadOS, macOS, and visionOS that allows you to customize HTTP request headers such as Accept, Accept-Language, Cookie, and User-Agent. ChangeTheHeaders is available now in the App Store.

I owe the idea for ChangeTheHeaders—as well as its name—to John Gruber of Daring Fireball. John came to me with a Safari problem, presumably because I’m the person who claims to stop the madness in Safari. John was wondering why dragging an image to Finder directly from a web page (content warning: political) produced a WebP file, whereas dragging the image opened in a new Safari tab produced a PNG file. That is puzzling! After some investigation, I discovered that the difference was the Accept HTTP request header, which specifies what types of response the web browser will accept. Safari’s default Accept header for images is this:

Accept: image/webp,image/avif,image/jxl,image/heic,image/heic-sequence,video/*;q=0.8,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5

Although image/webp appears first in the list, the order actually doesn’t matter. The quality value, specified by the ;q= suffix, determines the ranking of types. The range of values is 0 to 1, with 1 as the default value if none is specified. Thus, image/webp and image/png have equal precedence, equal quality value 1, leaving it up to the web site to decide which image type to serve. In this case, the web site decided to serve a WebP image, despite the fact that the image URL has a .png suffix. In a URL, unlike in a file path, the “file extension”, if one exists, is largely meaningless. A very simple web server will directly match a URL with a local file path, but a more complex web server can do almost anything it wants with a URL.

What happens when you select “Open Image in New Tab” from the Safari contextual menu? The name of the contextual menu item is slightly misleading, because Safari doesn’t use the already loaded image but rather loads the image URL anew in a new tab. Moreover, for some reason, Safari uses a different Accept header in this case:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Given a different request header, the web site decided to return a different image type, PNG. Don’t ask me why, because I don’t know! Again, image/webp and image/png have equal precedence here, so you could receive either one (or some other image type). This is what computer programmers call “undefined behavior”.

You now have my typically long-winded explanation of the problem, but what’s my solution to the problem? The behavior is caused by the Accept header, so if you want to change the behavior, you have to change the header, and while Safari itself has no settings to change its HTTP request headers, it does provide that capability to Safari extensions, which is where I come in. I considered and rejected the idea of a “stop the webp images” extension as far too niche for a product. However, some StopTheMadness Pro customers have requested similar features, such as the ability to spoof the User-Agent header. Thus, I decided to make a Safari extension that can customize any HTTP request headers, in the hope that a market exists for it. (Alas, Safari does not allow customization of HTTP response headers too.)

You might ask, why didn’t I just add this feature to StopTheMadness Pro? On macOS, StopTheMadness Pro is a Safari app extension, but the API to modify HTTP headers is available only to Safari web extensions, unfortunately. This is the same reason that StopTheMadness Pro doesn’t currently support Safari web apps.

Originally, my name for the new Safari extension was the unimaginative Override Headers. As the old saying goes, there are only two hard things in computer science, and one of them is naming things. When I told John Gruber that I had trouble coming up with a good name for the extension, he immediately brainstormed ChangeTheHeaders, riffing on my theme of StopTheMadness, StopTheScript, StopTheFonts, etc. I liked and indeed preferred his suggestion, but the app was practically done already (or so I believed at the time). It already had an app icon, based on the old app name. On the other hand, that app icon was amateurish and poorly designed… by me! So I turned once again to a true professional, Matthew Skiles, for a new app icon, based on the new name. I tip my hat to Matt!

New Safari extension: ChangeTheHeaders to customize HTTP request headers

What can you do with ChangeTheHeaders? I suspect the biggest selling point will be to spoof the User-Agent. The extension allows you to customize your User-Agent by URL domain. For example, you can make Safari pretend that it’s Chrome on Google web apps that give special treatment to Chrome. You can also customize the Accept-Language header if you don’t like the default language handling of some website, such as YouTube. (Why is the problem on the web always Google?) Or if you just want to deprioritize WebP images in Safari, you can do that, of course. It’s a simple matter of removing image/webp from the list. You probably don’t want to stop WebP entirely, because it may be the only image type available on some websites, but if you remove image/webp from the Accept header, then it no longer has the default quality value of 1. Instead, image/webp would fall under the wildcard image/*;q=0.8 specification, with a lower priority than explicit image types such as image/png. More information on how to configure ChangeTheHeaders is in the fine manual.

I hope that you find ChangeTheHeaders useful. Get it now in the App Store!



Source link

Postagens Similares

  • 📚 Flybot – Kev Quirk

    Autor: Dennisa E. TayloraMoja ocena: 👍🏻👍🏻 (okej) Fizyk Philip Moray ma dobry dzień. Kończy swój wielki projekt. Obiad w stołówce jest przynajmniej jadalny. Nie może się doczekać drinka na koniec dnia i kąpieli w wannie z hydromasażem. Następnie w jego biurze pojawia się dziwne urządzenie. Kawałek technologii, którego nigdy wcześniej nie widział – i który…

  • 評論:夜行者(馬克·羅森)

    夜人 故意是「無人問津的馬克朗森的書」。這不是關於贏得格萊美獎的超級製作人,而是關於這位工作 DJ 多年來“拖著板條箱進入酒吧和夜總會”、閱覽室並點燃舞池。 自始至終,羅森都坦誠地談論毒品和夜生活的過度。他講述了在隧道中混合物質、意外吸食海洛因、看著人們滑入 K 洞的經歷,並展示了這個世界是多麼令人興奮和殘酷。他聲稱正是焦慮和恐慌發作使他擺脫了毒癮。 這本書同樣誠實地講述了他成長的環境和特權世界。從搖滾明星繼父米克瓊斯(《外國人》中的主音吉他手,他可以悄悄地「借用​​」一箱箱放克和靈魂音樂)到以他上大學為條件為他買下 Technics 的母親,到他祖父設立的信託基金安全網,以及普遍接近成名的生活。儘管如此,Ronson 對 DJ 和這項特權似乎打開的側門總是很謙虛,例如在其他人苦苦掙扎多年的時候直接進入 Peter Gatien 的美國俱樂部。 對於大多數 DJ 來說,進入加蒂恩的俱樂部意味著在獲得 Club USA 的一席之地之前要在小酒吧和燈光昏暗的密室裡進行多年的表演。我應該需要那麼長時間來建立聯繫,逐漸向上。相反,我偶然發現了它。我已經擁有大多數其他人所沒有的優勢。我媽媽買了裝備給我。我是由一位擁有家庭工作室的音樂家撫養長大的。但即使對我來說,這也是一個荒謬的幸運突破。參加美國俱樂部比賽的想法是超現實的。我覺得對於這麼大的舞台來說太綠了。但我沒有辦法拒絕它。 資料來源:《夜行人》馬克‧羅森 (Mark Ronson) 著 我發現這本書的有趣之處在於羅森如何帶我們了解一門看似失傳的藝術。他講述了在 Rock and Soul 購買第一張套牌的經歷,弄清楚這一切是如何運作的,學習閱讀不同的房間和觀眾,透過 BPM 在黏性標籤上構建套牌,轟炸、咬合、改進,並慢慢贏得尊重。我對他打電話給年長的同學曼尼·艾姆斯 (Manny Ames) 詢問刮盤課程的經驗特別感興趣。 “你有貼紙嗎?”我爭先恐後地尋找一些麥克賽爾盒式磁帶標籤。他隨意地把它們撕下來,並向我展示瞭如何通過將貼紙從中心孔向外粘貼,就像指南針上的針一樣,對同一張唱片的兩份副本進行標記。「這樣,當您來回運行兩張唱片時,您將始終知道自己在視覺上的位置,」他說,並分享了一些既簡單又令人興奮的事情。貼紙使他能夠透過追蹤唱片的每轉,將唱片旋轉回精確的位置——2 點鐘、7 點鐘等。鐘面上的每個位置都對應於特定的聲音:大鼓可能位於 3 點鐘位置,軍鼓位於 9 點鐘位置,這樣就可以一致地找到並重複節拍的任何部分。 資料來源:《夜行人》馬克‧羅森 (Mark Ronson) 著 憑藉這一洞察力,羅森證明了成功只是時間,而不是魔法。(1) 這包括每週八場演出,口袋裡裝著無窮無盡的演示磁帶,週二晚上在狹小的房間裡演奏。 Ronson 在觀看 DJ AM 使用兩張唱片重新排序歌詞後指出了努力和練習的地方。 「老兄。你是怎麼學會這些東西的?!!」我問,仍在嘗試處理。「夥計……剛剛在嬰兒床裡觀看了老DMC的戰鬥並自學了常規。當你戒掉可卡因時你能做什麼,真是太瘋狂了。」他咯咯地笑了一聲,吸了一口煙。看著散落一地的…

  • Прогнозы моей ансамблевой модели CDC по Covid-19 — обновление на 05.09.20

    Оценка смертности от инфекций и уровня смертности Если бы мы знали количество инфекций и знали уровень смертности от инфекций (IFR), было бы очень просто спрогнозировать количество смертей на основе количества инфекций. Однако на протяжении всей пандемии мы оценивали как количество инфекций, так и IFR, и во многих случаях делали это плохо. Цифры также сильно различаются…

  • Taste of Beauty – Cuisine gastronomique à base de plantes

    {“@context”:”http:\/\/schema.org\/”,”@id”:”https:\/\/johnchow.com\/taste-of-beauty-plant-based-fine-dining\/#arve-youtube-h-tj_8kirxa-2″,”type”:”VideoObject”, “embedURL”: https:\/\/www.youtube-nocookie.com\/embed\/H-Tj_8KiRXA?feature=oembed&iv_load_policy=3&modestbranding=1&rel=0&autohide=1&playsinline=0&autoplay=0″} Taste of Beauty à Fountain Valley est un restaurant gastronomique à base de plantes où les ingrédients frais et de saison deviennent des œuvres d’art que vous pouvez voir, sentir, toucher et goûter. Le menu est conçu pour nous rappeler la beauté à couper le souffle de cette planète où nous vivons. Chaque…

  • Video: el programa de entrevistas nocturno de Jimmy Kimmel en el aire

    El ABC de Disney está tomando el programa de entrevistas nocturno de Jimmy Kimmel en el aire indefinidamente en medio de una controversia sobre sus recientes comentarios sobre el presunto asesino de Charlie Kirk. El presidente de Trump de la Comisión Federal de Comunicaciones, alineado el miércoles por “tomar medidas” contra Disney y ABC sobre…

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *