0

I have a S3 static page in a bucket and have added a Cloudfront distribution in front of it to access the webpage.

Now my question is: Is it possible to read the headers received by the webpage when the page is loaded? Is there a way I can print the headers on the webpage ?

Note: Im NOT about the response headers or the request headers before making a call from the client like mentioned over here: Accessing the web page's HTTP Headers in JavaScript

Im asking the same question as over here: Is it possible to read a request header from client javascript? for which there is no answer

  • 1
    Does this answer your question? [How do I access the HTTP request header fields via JavaScript?](https://stackoverflow.com/questions/220149/how-do-i-access-the-http-request-header-fields-via-javascript) – David Buck Apr 20 '20 at 13:19
  • Never mind I just understood that it is not possible from here: https://stackoverflow.com/questions/220149/how-do-i-access-the-http-request-header-fields-via-javascript – user3486822 Apr 20 '20 at 09:53

1 Answers1

1

You cannot access to the HTTP headers from your script, and this is the reason. HTTP is a client-server protocol, the server which receives the HTTP request headers is the S3 HTTP server. An HTTP GET request looks like this:

GET /index.html HTTP/1.1
Host: www.yours3bucketurl.com
User-Agent: client name

As you can see, the HTTP server uses that header to determine, what resource it should response with, in this case index.html. Then that index.html page is sent to the client and the request is over. There is not a chance that the JavaScript code contained in, or called from index.html, have access to that HTTP GET request, only the server knows. In other words, the content of index.html is just a resource returned from an HTTP server.

Andrés Muñoz
  • 559
  • 3
  • 8