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

d.o's GitLab instance 403s if User-Agent is absent or empty #1587

Merged
merged 1 commit into from Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Command/App/NewFromDrupal7Command.php
Expand Up @@ -148,6 +148,9 @@
return Command::FAILURE;
}
}
// PHP defaults to no user agent. (Drupal.org's) GitLab requires it.
// @see https://www.php.net/manual/en/filesystem.configuration.php#ini.user-agent
ini_set('user_agent', 'ACLI');

Check warning on line 153 in src/Command/App/NewFromDrupal7Command.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "FunctionCallRemoval": --- Original +++ New @@ @@ return Command::FAILURE; } } - // PHP defaults to no user agent. (Drupal.org's) GitLab requires it. - // @see https://www.php.net/manual/en/filesystem.configuration.php#ini.user-agent - ini_set('user_agent', 'ACLI'); + $recommendations_resource = fopen($recommendations_location, 'r'); $recommendations = Recommendations::createFromResource($recommendations_resource); fclose($recommendations_resource);
Copy link
Contributor

Choose a reason for hiding this comment

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

Guzzle HTTP client is the idiomatic way of making web requests in ACLI. For example:

$this->httpClient->request('GET', $downloadUrl, ['sink' => $localFilepath]);

I opened CLI-1160 and CLI-1161 to set the user agent for Guzzle requests and replace instances of fopen with Guzzle. Let me know if you anticipate any problems with that.

If there's some reason we can't use Guzzle, I'd prefer to set the user agent via a stream context for fopen rather than ini_set.

$recommendations_resource = fopen($recommendations_location, 'r');
$recommendations = Recommendations::createFromResource($recommendations_resource);
fclose($recommendations_resource);
Expand Down