1

I am trying to develop a chrome tool to spoof HTTP request and response headers. Request spoofing works fine. This code changes UA in request header but in response header I can't change anything. e.g. I am trying to change "Set-Cookie" but it won't work. I have used two codes for response. Here's my code:

Request

var requestFilter = {
    urls: [ "<all_urls>" ]
  },

  extraInfoSpec = ['requestHeaders','blocking'],

  handler = function( details ) {

    var headers = details.requestHeaders,
      blockingResponse = {};

    for( var i = 0, l = headers.length; i < l; ++i ) {
      if( headers[i].name == 'User-Agent' ) {
        headers[i].value = 's';
        break;
      }
    }

    blockingResponse.requestHeaders = headers;
    return blockingResponse;
  };

chrome.webRequest.onBeforeSendHeaders.addListener( handler, requestFilter, extraInfoSpec );

Response

    chrome.webRequest.onHeadersReceived.addListener(function(details){
    details.responseHeaders[details.responseHeaders.length] = {name: 'Set-Cookie', value: 'some random value'};
    return {responseHeaders: details.responseHeaders};

    },{urls:["<all_urls>"],types:["xmlhttprequest","sub_frame"]},
    ["responseHeaders","blocking"]); 

Response 2

    var responseListener = function(details){
    var rule = {
        "name": "Set-Cookie",
        "value": "Some Random Value"
    };
    details.responseHeaders.push(rule);
    return {responseHeaders: details.responseHeaders};
    };

    chrome.webRequest.onHeadersReceived.addListener(responseListener,
     {urls: [   "*://*/*" ] },
     ["blocking", "responseHeaders"]);
  • 1
    "*I am having a problem*" is not descriptive enough. Care to add ([edit]) details in your question? – PM 77-1 Jul 13 '15 at 23:06
  • I have edited my question "I am having a problem" means my code doesn't spoof information in response header. However it does in request header e.g. User Agent – Curtis Hagen Jul 14 '15 at 06:17
  • Isn't this a duplicate question? See [that](http://stackoverflow.com/questions/18310484/chrome-extension-modifying-http-response). – wOxxOm Jul 14 '15 at 09:30
  • FYI, response header spoofing works fine for most headers, but the devtools will only display the original response headers. How did you determine that "header spoofing does not work"? – Rob W Jul 14 '15 at 15:51
  • There is a chrome extension "Live HTTP Header". I use this tool to see my results i.e. user agents, referrer and others – Curtis Hagen Jul 14 '15 at 22:14
  • @wOxxOm Check the question.again at http://stackoverflow.com/questions/18310484/chrome-extension-modifying-http-response The guy asked to change "HTTP response's body" not "Header" – Curtis Hagen Jul 14 '15 at 22:16
  • @PM77-1 that's it! No answers ? – Curtis Hagen Jul 16 '15 at 10:00

0 Answers0