Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add plugin - cache control #810

Merged
merged 9 commits into from
Mar 12, 2024

Conversation

LeBW
Copy link
Contributor

@LeBW LeBW commented Feb 1, 2024

Ⅰ. Describe what this PR did

feat: add plugin - cache control.

Ⅱ. Does this pull request fix one issue?

fixes #621

功能说明

cache-control插件实现了基于 URL 文件后缀来为请求的响应头部添加 ExpiresCache-Control 头部,从而方便浏览器对特定后缀的文件进行缓存,例如 jpgpng 等图片文件。

配置字段

名称 数据类型 填写要求 默认值 描述
suffix string 必填,表示匹配的文件后缀名,例如 jpgpng 等。如果需要匹配多种后缀,需要用 | 进行分割,例如 png|jpg - 配置用于匹配的请求文件后缀
maxAge int 必填,表示缓存的最长时间,单位为秒。例如需要缓存1小时,需填写 3600 - 配置缓存的最大时间

配置示例

屏蔽请求 url 路径

suffix: jpg|png|jpeg
maxAge: 3600

根据该配置,下列请求在访问时,将会在响应头中添加 ExpiresCache-Control 字段,且过期时间为 1 小时后。

curl http://example.com/test.png
curl http://exmaple.com/test.jpg

@johnlanni
Copy link
Collaborator

@LeBW 有几个修改建议:

  1. 建议suffix作为选填,用可以根据路由生效。如果填了suffix则额外根据suffix做判断;
  2. nginx的三种模式建议都兼容下 :time/epoch/max
    image
  3. 需要补充一下E2E测试用例

@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 38.16%. Comparing base (c9f1f94) to head (4a5b903).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #810      +/-   ##
==========================================
+ Coverage   38.13%   38.16%   +0.02%     
==========================================
  Files          61       61              
  Lines       10436    10436              
==========================================
+ Hits         3980     3983       +3     
+ Misses       6156     6154       -2     
+ Partials      300      299       -1     

see 1 file with indirect coverage changes

@johnlanni
Copy link
Collaborator

@LeBW CI没通过,麻烦更新下 proxy-wasm-go 这个lib的依赖,目录改到 higress-group 下了

@johnlanni
Copy link
Collaborator

@LeBW go文件需要添加下copyright

Copy link
Collaborator

@johnlanni johnlanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johnlanni johnlanni merged commit 32b6027 into alibaba:main Mar 12, 2024
11 checks passed
@ZJfans
Copy link

ZJfans commented Mar 12, 2024

@johnlanni
有一个疑问,no cache需要服务端生成Etag与last-modified,并对请求的If-Modified-Since与If-None-Match进行新鲜度校验,好像没有看到有这个逻辑。
还有个建议是,要不要考虑兼容http1.0,Pragma: no-cache。

@johnlanni
Copy link
Collaborator

@ZJfans Higress没有静态文件代理的能力,只能代理请求到后端,没法知道资源有没有发生变更,所以无法支持etag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add support of expires extension like nginx.
4 participants