Fixing Live HTTP Headers 0.17 Add-on

Live HTTP Headers is a great little add-on for Firefox allowing user to replay or modify HTTP requests. Unfortunately it seems the replay button has stopped working with recent Firefox versions and I decided to make a temporary fix until the official version is updated.

After looking for what could be the cause of the replay button not working I found out that headers containing If-Modified-Since would be replayed properly. If-Modified-Since is a way to tell spiders (those little things search engines use to index your website pages) that this page has been changed since a specific date: "The If-Modified-Since request-header field is used with a method to make it conditional: if the requested variant has not been modified since the time specified in this field, an entity will not be returned from the server; instead, a 304 (not modified) response will be returned without any message-body". For more details about it you can visit the W3 RFC 2616 Page.

Let's force Live HTTP Headers to send the replay by modifying the Add-on source and adding this field ourselves. All Firefox add-ons are stored in your profile folder, to find out where this folder is run Firefox, go to Help -> Troubleshooting Information. Or enter the url about:support. Inside the table named Application Basics you will see a row named Profile Folder with a button Show Folder, clicking the button will open the folder in your file manager for you. On Linux it's in your home directory: ~/.mozilla/firefox/[profile]

Now don't close Firefox yet and look at the table named Extensions find the row with Live HTTP Headers and note the ID number somewhere. Back to your file manager go to the folder extensions, you should find the same ID in it. This is the install folder of the Live HTTP Headers add-on:

Fixing Live HTTP Headers 0.17 Add-on - 01

Inside the chrome folder you will find the actual source of the add-on:

Fixing Live HTTP Headers 0.17 Add-on - 02

The file livehttpheaders.jar contains all the source, this is not a Java Archive JAR file, it's simply a ZIP file renamed with .jar extension. Make a backup of this file (just in case):

Fixing Live HTTP Headers 0.17 Add-on - 03

And copy this file while renaming it with a .zip extension.

Fixing Live HTTP Headers 0.17 Add-on - 04

After extracting the content you should be able to see this:

Fixing Live HTTP Headers 0.17 Add-on - 05

And inside the content folder you will now be able to see Live HTTP Headers source:

Fixing Live HTTP Headers 0.17 Add-on - 06

Close Firefox and edit the file LiveHTTPReplay.js, this is the file invoked when we want to replay a http header and we want to modify it to add our If-Since-Modified field. From what I understand, the method livehttpheaders.replay.init is called after pressing the replay button from the main window. Modifying its initialization process should be the easiest way to add our own header fields. Let's see how it looks:

if(!livehttpheaders) var livehttpheaders={};
if(!livehttpheaders.replay) livehttpheaders.replay={};

livehttpheaders.replay.live = window.arguments[0];
livehttpheaders.replay.init = function() {
var args = window.arguments;

document.getElementById("livehttpheaders.replay.method").value = args[1];
document.getElementById("livehttpheaders.replay.url").value = args[2];
document.getElementById("livehttpheaders.replay.version").value = args[3];
document.getElementById("livehttpheaders.replay.headers").value = args[4];
if (args[5] != null) {
document.getElementById("livehttpheaders.replay.post").value = livehttpheaders.replay.stringToEscape(args[5]);
document.getElementById("livehttpheaders.replay.sendpost").checked="true";
}

livehttpheaders.replay.updatePost();
}

Since we want to add our own header field we will simply edit the "livehttpheaders.replay.headers" line and add our own value to args[4]. This is a simple string operation. After our tiny patch the method looks like this:

if(!livehttpheaders) var livehttpheaders={};
if(!livehttpheaders.replay) livehttpheaders.replay={};

livehttpheaders.replay.live = window.arguments[0];
livehttpheaders.replay.init = function() {
var args = window.arguments;

document.getElementById("livehttpheaders.replay.method").value = args[1];
document.getElementById("livehttpheaders.replay.url").value = args[2];
document.getElementById("livehttpheaders.replay.version").value = args[3];
// This is our tiny patch here --------------
document.getElementById("livehttpheaders.replay.headers").value = args[4] + "If-Modified-Since: *\n";
// ------------------------------------------
if (args[5] != null) {
document.getElementById("livehttpheaders.replay.post").value = livehttpheaders.replay.stringToEscape(args[5]);
document.getElementById("livehttpheaders.replay.sendpost").checked="true";
}

livehttpheaders.replay.updatePost();
}

Notice + "If-Modified-Since: *\n", this is all we need to add to make Live HTTP Headers work again. Now to apply our changes to the add-on it's really simple, just make a ZIP archive of all the content the file livehttpheaders.jar originally had. Meaning the folder content, locale, skin. And be sure to have the exact file name and extension: livehttpheaders.jar (not ending in .zip but .jar)

Restart Firefox, try the replay button of Live HTTP Headers. It is now working again.