diff --git a/releasenotes.txt b/releasenotes.txt index bb2a7bd..922bac6 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -1,5 +1,19 @@ -- Release Notes -- +Release 0.7.1.2, 21 March 2012 + +* The Modify action now supports replacing a header based on a regex in the value field. + Any string in the value for a Modify action which matches the form /foo/bar/ triggers the code. + foo can be a regular expression and bar is the string which replaces the match. + Example: + Action: Modify + Name: Host + Value: {^w{0,3}\.?domain.com$}{192.168.254.65} + This will change www.domain.com and domain.com to 192.168.254.65 if found in the Host header. + (Updated 28th) + +-- + Release 0.7.1.1, 30 November 2011 * Fixed bug 24593: Addon toolbar is displayed every time a new window is opened diff --git a/src/components/modifyheaders-service.js b/src/components/modifyheaders-service.js index e82f503..6c87fb8 100644 --- a/src/components/modifyheaders-service.js +++ b/src/components/modifyheaders-service.js @@ -273,8 +273,20 @@ if (!ModifyHeaders.Proxy) { // This is the default for action = Modify var headerValue = headers[i].value; var headerAppend = false; - - if (headers[i].action == "Add") { + + // Could add a new action "Regex" instead. + // For the following code to run, the value supplied by the user + // should be of the form: {foo}{bar} + // where 'foo' can be a regular expression + // and 'bar' is the string to replace the match with. + if(headers[i].action == "Modify") { + var isRegex = headerValue.match(/^\{(.*?)\}\{(.*?)\}$/); + if(isRegex.length>0) { // OR == 2 to be stricter + var currentHeaderValue = subject.getRequestHeader(headerName); + // 0 = {foo}{bar}; 1 = foo; 2 = bar; + headerValue = currentHeaderValue.replace(new RegExp(isRegex[1]), isRegex[2]); + } + } else if (headers[i].action == "Add") { headerAppend = true; } else if (headers[i].action == "Filter") { headerValue = "";