Proo1931
Proo1931

Reputation: 103

How I can block some of the HTTP headers fields?

For example the page is sending a 'link' http headers field that I don't want to load an async CSS from. How can I block it? Is it possible that I get those headers, remove the LINK field from it, and then page will load without this addition CSS (non-placed in page body)?

I have tried to modify the headers to no avail.

request('https://www.google.com', function(err, resp, data){
  if (resp.statusCode == 200) {
    console.log(resp.headers); // headers
  }
  else {console.log(err);}
});

Request is a node.js module. I need to modify headers before they are loaded by browser (passing modified headers by 'render' with combination of ejs template is not working).

Upvotes: 0

Views: 1354

Answers (2)

shaochuancs
shaochuancs

Reputation: 16276

Update: The OP is talking about "Web Linking", the RFC5988 stuff on prefetch resource with HTTP response header, and want to block such prefetch behaviour.

In order to do that, a proxy can be made manually, block all unwanted data, and only return HTTP headers and content of interest. For example:

router.get('/proxy-to-google', function(req, res) {
  request('https://www.google.com', function(err, resp, data) {
    // get interested headers from resp object, and set it in res
    res.set('Example-Header', 'XXX');
    ...
    res.send(data);
  });  
});

There are 3 types of head/header in the world of web, and it seems you have confused with these concepts.

  1. HTTP header. These are the header information delivered in HTTP request and response. In the example of question, the HTTP response headers are printed.
  2. <header> element in HTML. These are visible element exists in HTML page body, mostly used to wrap elements such as title, navigation bar etc.
  3. <head> element in HTML. This is the meta element of HTML document. It is not visible in page, but rather responsible to mark important information of HTML document, such as CSS stylesheet links, JavaScript file URLs etc.

In your case, you are trying to block the 3rd kind of "head" above, and you can make it using @Zuei Zukenberg's proposal. This <head> element has nothing to do with HTTP headers.

Upvotes: 0

Zuei Zukenberg
Zuei Zukenberg

Reputation: 81

Yes, its possible to remove the css and js links (they are not headers) from the html response and just display the result using jsdom or cheerio.

Upvotes: 2

Related Questions