EzDevInfo.com

http-headers interview questions

Top http-headers frequently asked interview questions

How can I add a custom HTTP header to ajax request with js or jQuery?

Does anyone know how to add or create a custom HTTP header using JavaScript or jQuery?


Source: (StackOverflow)

What's the difference between Cache-Control: max-age=0 and no-cache?

The header Cache-Control: max-age=0 implies that the content is considered stale (and must be re-fetched) immediately, which is in effect the same thing as Cache-Control: no-cache.

Google has failed to solve this mystery for me :(


Source: (StackOverflow)

Advertisements

403 Forbidden vs 401 Unauthorized HTTP responses

For a web page that exists, but for which a user that does not have sufficient privileges, (they are not logged in or do not belong to the proper user group), what is the proper HTTP response to serve? 401? 403? Something else? What I've read on each so far isn't very clear on the difference between the two. What use cases are appropriate for each response?


Source: (StackOverflow)

Proper MIME media type for PDF files

When working with PDFs, I've run across the MIME types application/pdf and application/x-pdf among others.

Is there a difference between these two types, and if so what is it? Is one preferred over the other?

I'm working on a web app which must deliver huge amounts of PDFs and I want to do it the correct way, if there is one.


Source: (StackOverflow)

Making sure a web page is not cached, across all browsers

Our investigations have shown us that not all browsers respect the http cache directives in a uniform manner.

For security reasons we do not want certain pages in our application to cached, ever, by the web browser. This must work for at least the following browsers:

  • Internet Explorer 6+
  • Firefox 1.5+
  • Safari 3+
  • Opera 9+
  • Chrome

Our requirement came from a security test. After logging out from our website you could press the back button and view cached pages.


Source: (StackOverflow)

What does enctype='multipart/form-data' mean?

What does enctype='multipart/form-data' mean in an HTML form and when should we use it?


Source: (StackOverflow)

How to send a header using a HTTP request through a curl call?

I wish to send a header to my Apache server on a Linux box. How can I achieve this via a curl call?


Source: (StackOverflow)

Accessing the web page's HTTP Headers in JavaScript

How do I access a page's HTTP response headers via JavaScript?

Related to this question, which was modified to ask about accessing two specific HTTP headers.

Related:
How do I access the HTTP request header fields via JavaScript?


Source: (StackOverflow)

Can't get rid of header X-Powered-By:Express

I am running a server on nodejs with express. I can't seem to get rid of the header:

X-Powered-By:Express

I was wondering if there is any way to get rid of this header or do I have to live with it?


Source: (StackOverflow)

How do I read any request header in PHP

How should I read any header in PHP?

For example the custom header: X-Requested-With.


Source: (StackOverflow)

What's the "Content-Length" field in HTTP header?

What does it mean?

  1. Byte count of encoded content string with encoding specified in header.
  2. Character count of content string.

Especially in case of "Content-Type: application/x-www-form-urlencoded".


Source: (StackOverflow)

Add Header in AJAX Request with jQuery

I would like to add a custom header to an AJAX POST request from jQuery.

I have tried this:

$.ajax({
    type: 'POST',
    url: url,
    headers: {
        "My-First-Header":"first value",
        "My-Second-Header":"second value"
    }
    //OR
    //beforeSend: function(xhr) { 
    //  xhr.setRequestHeader("My-First-Header", "first value"); 
    //  xhr.setRequestHeader("My-Second-Header", "second value"); 
    //}
}).done(function(data) { 
    alert(data);
});

When I send this request and I watch with FireBug, I see this header:

OPTIONS xxxx/yyyy HTTP/1.1
Host: 127.0.0.1:6666
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Origin: null
Access-Control-Request-Method: POST
Access-Control-Request-Headers: my-first-header,my-second-header
Pragma: no-cache
Cache-Control: no-cache

Why do my custom headers go to Access-Control-Request-Headers:

Access-Control-Request-Headers: my-first-header,my-second-header

I was expecting a header values like this:

My-First-Header: first value
My-Second-Header: second value

Is it possible? Thanks.


Source: (StackOverflow)

Difference between application/x-javascript and text/javascript content types

What is the difference between these headers?

Content-Type: application/javascript
Content-Type: application/x-javascript
Content-Type: text/javascript

Which one is best and why?

Please do not say they are identical - if they were identical there would not have been two of them. I know both work - but I would like to know the difference.


Source: (StackOverflow)

Content-Disposition:What are the differences between "inline" and "attachment"?

What are the differences between

Response.AddHeader("Content-Disposition", "attachment;filename=somefile.ext")

and

Response.AddHeader("Content-Disposition", "inline;filename=somefile.ext")

I don't know the differences , because when I use one or another I always get a window prompt asking me to download the file for both of them. I read the specs, but it is clueless.


Source: (StackOverflow)

Maximum on http header values?

Is there an accepted maximum allowed size for HTTP headers? If so, what is it? If not, is this something that's server specific or is the accepted standard to allow headers of any size?


Source: (StackOverflow)