function advagg_relocate_try_failures_again in Advanced CSS/JS Aggregation 7.2
Detect failures and try again.
Parameters
array $responses: An array of $response objects from a http request.
2 calls to advagg_relocate_try_failures_again()
- advagg_relocate_get_remote_data in advagg_relocate/
advagg_relocate.advagg.inc - Gets external CSS and JS files; caches and returns response.
- advagg_relocate_get_remote_font_data in advagg_relocate/
advagg_relocate.advagg.inc - Gets external CSS files; caches it and returns css font rules.
File
- advagg_relocate/
advagg_relocate.advagg.inc, line 627 - Advanced aggregation relocate module.
Code
function advagg_relocate_try_failures_again(array &$responses) {
// Try failures again.
foreach ($responses as $key => &$response) {
// Strlen doesn't match.
if (!empty($response->headers['content-length']) && $response->headers['content-length'] > strlen($response->data)) {
$response->code = 0;
if (isset($response->options['headers']['connection'])) {
unset($response->options['headers']['connection']);
}
}
// Decode data.
$decode_ok = advagg_relocate_uncompress_data($response);
if (!$decode_ok) {
// If decoding failed try again.
if (isset($response->options['headers']['Accept-Encoding'])) {
unset($response->options['headers']['Accept-Encoding']);
}
$response->code = 0;
}
// Try again if code is empty.
if (empty($response->code)) {
$url = $response->url;
$options = $response->options;
$responses[$key] = drupal_http_request($url, $options);
if (!isset($responses[$key]->options)) {
$responses[$key]->options = $options;
}
if (!isset($responses[$key]->url)) {
$responses[$key]->url = $url;
}
}
}
// Try failures again, but force http.
foreach ($responses as $key => $response) {
if (empty($response->code)) {
$url = advagg_force_http_path($response->url);
$options = $response->options;
$responses[$key] = drupal_http_request($url, $options);
if (!isset($responses[$key]->options)) {
$responses[$key]->options = $options;
}
if (!isset($responses[$key]->url)) {
$responses[$key]->url = $url;
}
}
}
}