Set the setup-php user agent for tool downloads and Node fetches

This commit is contained in:
Shivam Mathur
2026-11-27 01:39:28 +05:30
parent 66f29b02f3
commit fad0ff9c5d
6 changed files with 18 additions and 7 deletions
+4
View File
@@ -21,6 +21,10 @@ it('checking fetch', async () => {
nock(host_url)
.get('/manifest')
.matchHeader(
'user-agent',
`setup-php (${process.platform}; ${process.arch}; +https://setup-php.com)`
)
.reply(200, {latest: 'latest'})
.get('/manifest')
.matchHeader('authorization', 'Bearer invalid_token')
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -16,7 +16,7 @@ export async function fetch(
redirect_count = 5
): Promise<Record<string, string>> {
const headers: Record<string, string> = {
'User-Agent': `Mozilla/5.0 (${process.platform} ${process.arch}) setup-php`
'User-Agent': `setup-php (${process.platform}; ${process.arch}; +https://setup-php.com)`
};
if (auth_token) {
headers['Authorization'] = 'Bearer ' + auth_token;
+3 -2
View File
@@ -304,9 +304,10 @@ Function Add-Tool() {
} else {
$backup_path = "$tool_path.bak"
if (Test-Path $tool_path) { Copy-Item $tool_path -Destination $backup_path -Force }
$user_agent = "setup-php ($env:RUNNER_OS; $env:RUNNER_ARCH; +https://setup-php.com)"
foreach ($url in $urls){
try {
$status_code = (Invoke-WebRequest -Passthru -Uri $url -OutFile $tool_path).StatusCode
$status_code = (Invoke-WebRequest -Passthru -Uri $url -UserAgent $user_agent -OutFile $tool_path).StatusCode
} catch {
$status_code = 0
if($url -match '^https://github\.com/[^/]+/[^/]+/releases/latest/download/[^/?#]+$') {
@@ -314,7 +315,7 @@ Function Add-Tool() {
$release_url = Get-LastRelease $url
if ($release_url) {
$url = $release_url
$status_code = (Invoke-WebRequest -Passthru -Uri $url -OutFile $tool_path).StatusCode
$status_code = (Invoke-WebRequest -Passthru -Uri $url -UserAgent $user_agent -OutFile $tool_path).StatusCode
}
} catch {
$status_code = 0
+8 -2
View File
@@ -224,6 +224,12 @@ get_last_release() {
done
}
# Download a tool with the setup-php user agent.
download_tool() {
local curl_opts=("${curl_opts[@]}" -A "setup-php ($RUNNER_OS; $RUNNER_ARCH; +https://setup-php.com)")
get -v -e "$@"
}
# Function to setup a remote tool.
add_tool() {
url=$1
@@ -266,12 +272,12 @@ add_tool() {
# Tools are single files, so let servers gzip them in transit when curl can decode it.
local curl_opts=("${curl_opts[@]}")
curl -V | grep -qw libz && curl_opts+=(--compressed)
status_code=$(get -v -e "$tool_path" "${url[@]}")
status_code=$(download_tool "$tool_path" "${url[@]}")
if [ "$status_code" != "200" ] && [[ "${url[0]}" =~ ^https://github\.com/[^/]+/[^/]+/releases/latest/download/[^/?#]+$ ]]; then
local release_url
if release_url=$(get_last_release "${url[0]}"); then
url[0]="$release_url"
status_code=$(get -v -e "$tool_path" "${url[0]}")
status_code=$(download_tool "$tool_path" "${url[0]}")
fi
fi
if [ "$status_code" = "200" ]; then
+1 -1
View File
@@ -1,7 +1,7 @@
# Variables
export tick="✓"
export cross="✗"
export curl_opts=(-sL -A "setup-php (+https://github.com/shivammathur/setup-php)")
export curl_opts=(-sL)
export old_versions="5.[3-5]"
export jit_versions="8.[0-9]"
export php_builder_versions="8.[3-9]"