Hidden features of HTTP

2019-03-07 09:18发布

What hidden features of HTTP do you think are worth mentioning?

By hidden features I mean features that already are part of the standard but widely rather unknown or unused.

Just one feature per answer please.

标签: http
13条回答
Anthone
2楼-- · 2019-03-07 09:50

In Dynamic content use Last_Modified or ETag header

At times you have dynamic content that can be large and/or costly to generate and that may not change from request to request. You can add a Last_Modified or ETag header to the your generated response.

At the top of your expensive dynamic code you can use the If_Modified_Since or the If_None_Match to determine if the content requestor already has is still current. If it is change the response status to "304 Unmodified" and end the request.

Some server-side technologies provide such features formally but you can do the above even in lowly ASP-Classic.

Note this differs from setting Cache-Control, Expires headers in that it ensures the client always has the latest info on request.

查看更多
聊天终结者
3楼-- · 2019-03-07 09:52

You can request to resume a (large) HTTP response (e.g. file download) using Range and If-Range request headers with respectively the specified byte range and the unique file identifier or the file modification timestamp. This is possible if the server has sent the Accept-Ranges: bytes and ETag or Last-Modified response headers on the initial response with respectively the notification that the server supports byte range requests, the unique file identifier and the file modification timestamp.

The initial response can look like (the ETag is usually composed of file name, size and last modification timestamp):

Accept-Ranges: bytes
ETag: file.ext_1234_1234567890
Content-Range: bytes 0-1233/1234

When the download get aborted on for example 1KB (1024 bytes), the client can resume it as follows:

If-Range: file.ext_1234_1234567890
Range: bytes=1024-

Which should return this response with the appropriate bytes in the body:

Accept-Ranges: bytes
ETag: file.ext_1234_1234567890
Content-Range: bytes 1024-1233/1234
查看更多
\"骚年 ilove
4楼-- · 2019-03-07 09:58

It's got to be the 418 I'm a teapot status code, part of the Hyper Text Coffee Pot Control Protocol (an extension to HTTP). Makes me laugh every time.

2.3.2 418 I'm a teapot

Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot". The resulting entity body MAY be short and stout.

查看更多
狗以群分
5楼-- · 2019-03-07 09:58

ReST tries to push HTTP to its limits as an interface protocol.

It's not a hidden feature, but from looking at well-defined ReST APIs one can get quite a nice grip on how HTTP is meant to work and find wonderful examples of what can be achieved with simple combination of HTTP methods, status codes and headers to and fro.

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-03-07 10:00

HTTP 100 (Continue) Status

A client can send a request message with a request body to determine if the origin server is willing to accept the request..

In some cases, it might either be inappropriate or highly inefficient for the client to send the body if the server will reject the message without looking at the body.

Could be used to avoid traffic from rogue clients.. and/or where bandwidth is a precious commodity.

However, for full use of this feature there are some criteria for HTTP1.1 Client, Servers and Proxies. See the HTTP/1.1 RFC 2616 for further reading on HTTP Connections.

查看更多
Melony?
7楼-- · 2019-03-07 10:01

Trailer (in contrast to Header)

查看更多
登录 后发表回答