Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
Add support for overriding the User-Agent header to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
gmta committed Jun 10, 2022
1 parent 01f8789 commit fabb61b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ MIRROR_PACKAGIST_TYPE=composer
#MIRROR_PACKAGIST_AUTH_TYPE=basic
#MIRROR_PACKAGIST_AUTH_USERNAME=
#MIRROR_PACKAGIST_AUTH_PASSWORD=
#MIRROR_PACKAGIST_USER_AGENT=
1 change: 1 addition & 0 deletions proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ For every mirror, the following configuration options are available:
| `MIRROR_{name}_AUTH_TYPE` | No | Always `basic` (default) | Type of upstream authentication |
| `MIRROR_{name}_AUTH_USERNAME` | No | String | Username for basic authentication |
| `MIRROR_{name}_AUTH_PASSWORD` | No | String | Password for basic authentication |
| `MIRROR_{name}_USER_AGENT` | No | String | User Agent header sent to upstream |

For time and size unit syntax, see: http://nginx.org/en/docs/syntax.html

Expand Down
3 changes: 2 additions & 1 deletion proxy/templates/proxy.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ENV.keys.map { |key| key.to_s }
:auth_type => ENV["MIRROR_#{name}_AUTH_TYPE"] || 'basic',
:auth_user => ENV["MIRROR_#{name}_AUTH_USERNAME"] || '',
:auth_pass => ENV["MIRROR_#{name}_AUTH_PASSWORD"] || '',
:user_agent => ENV["MIRROR_#{name}_USER_AGENT"] || 'Velocita Composer Cache',
}
end

Expand Down Expand Up @@ -138,7 +139,7 @@ server {

proxy_set_header Connection '';
proxy_set_header Host $proxy_host;
proxy_set_header User-Agent 'Velocita Composer Cache';
proxy_set_header User-Agent '<%= mirror[:user_agent] %>';
<%- case mirror[:auth_type] -%>
<%- when 'basic' -%>
<%- unless mirror[:auth_user].empty? || mirror[:auth_pass].empty? -%>
Expand Down

0 comments on commit fabb61b

Please sign in to comment.