Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Use Drupal httpClient to ensure server is not slowed down for invalid urls. #71

Merged
merged 1 commit into from
Sep 17, 2018

Conversation

bibliophileaxe
Copy link
Contributor

We are using file_get_contents for downloading files. We can use \Drupal::httpClient() instead to download file and make it fast. This also sets a server timeout of 30seconds for invalid urls.


// Check to ensure errors like 404, 403, etc. are catched and empty file
// not saved in SKU.
$client = \Drupal::httpClient();
Copy link
Contributor

Choose a reason for hiding this comment

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

can you inject this through constructor please?

Copy link
Contributor Author

@bibliophileaxe bibliophileaxe Sep 17, 2018

Choose a reason for hiding this comment

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

@bibliophileaxe bibliophileaxe force-pushed the file-download branch 2 times, most recently from 4bc6e5b to 59fa614 Compare September 17, 2018 11:22
@miromichalicka miromichalicka merged commit 4c291a3 into acquia:8.x-1.x Sep 17, 2018
// not saved in SKU.
$client = \Drupal::httpClient();
try {
$file_data = $client->get($data['file']);

Choose a reason for hiding this comment

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

fixed usage of http client: #74

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

Successfully merging this pull request may close these issues.

3 participants