http

缓存

缓存

缓存设置

nginx 实例

缓存主要分为强缓存和对比缓存。

强缓存

强缓存即是在约定的时间内,不管服务器文件是否更新,都采用缓存文件,返回 200

max-age= 来设定时间,单位为 ss-maxage= 为代理服务器的缓存时间。

对比缓存

而对比缓存指,需要和远端文件对比(用 last-modifiedetag 来实现),如果没有修改返回 304,然后使用缓存;如果有修改,则返回 200,并附带新文件。

aab5d5fd-70c1-11e5-a4fb-b026b977eb28

request 示意

1. application/x-www-form-urlencoded

这种方式通常用于提交简单的表单数据。一个请求示例如下:

1
2
3
4
5
6
POST /test HTTP/1.1
Host: foo.example
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

field1=value1&field2=value2

只有 key 和 value 中的 Non-alphanumeric characters 才会 urlencoded?

2. multipart/form-data

这种方式用于文件上传或需要同时提交文本和文件。一个请求示例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
POST /test HTTP/1.1
Host: foo.example
Content-Type: multipart/form-data;boundary="boundary"

--boundary
Content-Disposition: form-data; name="field1"

value1
--boundary
Content-Disposition: form-data; name="field2"; filename="example.txt"

value2
--boundary--

3. raw

用于提交原始数据,如JSON。一个请求示例如下:

1
2
3
4
5
6
7
8
9
bashCopy code
POST /api HTTP/1.1
Host: example.com
Content-Type: application/json

{
"key1": "value1",
"key2": "value2"
}

4. binary

直接发送二进制数据,例如,上传一个图片文件。一个请求示例如下:

1
2
3
4
5
6
bashCopy code
POST /upload HTTP/1.1
Host: example.com
Content-Type: application/octet-stream

(binary data)

这些文本示意展示了HTTP请求的结构,包括方法(如POST)、路径(如/api或/upload)、主机(如Host: example.com)、内容类型(如Content-Type: application/json)以及请求体(根据提交方式的不同,请求体的格式也不同)。在实际应用中,需要根据服务器的要求和数据的具体情况选择合适的提交方式。

Data from forms is normally encoded using the “media type” application/x-www-form-urlencoded when it doesn’t include files.

But when the form includes files, it is encoded as multipart/form-data. If you use File, FastAPI will know it has to get the files from the correct part of the body.


http
https://lllei.top/2024/01/09/http 缓存/
作者
Lei
发布于
2024年1月9日
许可协议