Skip to content

Commit

Permalink
Create CI build workflow and optimize ETag module
Browse files Browse the repository at this point in the history
Add a GitHub Actions CI workflow for building and testing NGINX modules. In the ETag module, skip processing if the request has no upstream to improve efficiency.
  • Loading branch information
dvershinin committed Sep 6, 2024
1 parent 394ab89 commit 35473b5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
community_bridge: null
custom:
- https://paypal.me/dvershinin
github: dvershinin
issuehunt: null
ko_fi: null
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test Build

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 2
matrix:
nginx-branch: [stable, mainline]
steps:
- uses: actions/checkout@v3

- name: Install build and test dependencies
run: |
sudo apt-get --yes update
sudo apt-get install --yes libpcre3-dev libssl-dev perl cpanminus
- name: Create NGINX download directory
run: mkdir nginx

- name: Download ${{ matrix.nginx-branch }} NGINX
uses: dvershinin/lastversion-action@main
with:
repository: 'nginx'
action: 'unzip'
branch: ${{ matrix.nginx-branch }}
working_directory: ./nginx

- name: Configure NGINX to compile with the module statically
run: |
cd nginx && ./configure --with-debug --add-module=..
- name: Make NGINX
run: |
cd nginx && make -j$(nproc)
- name: Ensure Test::Nginx installed
run: |
cpanm --notest --local-lib=$HOME/perl5 Test::Nginx
- name: Test the module
run: |
PATH=$(pwd)/nginx/objs:$PATH PERL5LIB=$HOME/perl5/lib/perl5 TEST_NGINX_VERBOSE=true prove -v
11 changes: 10 additions & 1 deletion src/ngx_http_dynamic_etag_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ ngx_http_dynamic_etag_header_filter(ngx_http_request_t *r)
ngx_http_dynamic_etag_loc_conf_t *conf;
ngx_str_t enable;


conf = ngx_http_get_module_loc_conf(r, ngx_http_dynamic_etag_module);

// Skip processing if not fetching from upstream (e.g., FastCGI)
if (r->upstream == NULL) {
return ngx_http_next_header_filter(r);
}

if (conf->enable == 0 || r->method & NGX_HTTP_HEAD) {
return ngx_http_next_header_filter(r);
} else if (conf->enable == 2) {
Expand Down Expand Up @@ -211,6 +215,11 @@ ngx_http_dynamic_etag_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
unsigned char digest[16];
ngx_uint_t i;

// If the response is not from the upstream, skip processing
if (r->upstream == NULL) {
return ngx_http_next_body_filter(r, in);
}

ctx = ngx_http_get_module_ctx(r, ngx_http_dynamic_etag_module);
if (ctx == NULL) {
return ngx_http_next_body_filter(r, in);
Expand Down

0 comments on commit 35473b5

Please sign in to comment.