Revert "Fix IHTTPResult::getHeader() - Now returns a string array, like expected - Fix usages - Fix dataset"
This reverts commit 80bd0a4d
This commit is contained in:
parent
6fcbb9866f
commit
0449077126
11 changed files with 59 additions and 68 deletions
|
@ -491,8 +491,8 @@ class BBCode
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = $curlResult->getBody();
|
$i = $curlResult->getBody();
|
||||||
$contType = $curlResult->getContentType();
|
$type = $curlResult->getContentType();
|
||||||
$type = Images::getMimeTypeByData($i, $mtch[1], $contType);
|
$type = Images::getMimeTypeByData($i, $mtch[1], $type);
|
||||||
|
|
||||||
if ($i) {
|
if ($i) {
|
||||||
$Image = new Image($i, $type);
|
$Image = new Image($i, $type);
|
||||||
|
|
|
@ -424,17 +424,16 @@ class Photo
|
||||||
if (!empty($image_url)) {
|
if (!empty($image_url)) {
|
||||||
$ret = DI::httpRequest()->get($image_url, true);
|
$ret = DI::httpRequest()->get($image_url, true);
|
||||||
$img_str = $ret->getBody();
|
$img_str = $ret->getBody();
|
||||||
$contType = $ret->getContentType();
|
$type = $ret->getContentType();
|
||||||
} else {
|
} else {
|
||||||
$img_str = '';
|
$img_str = '';
|
||||||
$contType = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($quit_on_error && ($img_str == "")) {
|
if ($quit_on_error && ($img_str == "")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = Images::getMimeTypeByData($img_str, $image_url, $contType);
|
$type = Images::getMimeTypeByData($img_str, $image_url, $type);
|
||||||
|
|
||||||
$Image = new Image($img_str, $type);
|
$Image = new Image($img_str, $type);
|
||||||
if ($Image->isValid()) {
|
if ($Image->isValid()) {
|
||||||
|
|
|
@ -1005,13 +1005,13 @@ class User
|
||||||
$curlResult = DI::httpRequest()->get($photo, true);
|
$curlResult = DI::httpRequest()->get($photo, true);
|
||||||
if ($curlResult->isSuccess()) {
|
if ($curlResult->isSuccess()) {
|
||||||
$img_str = $curlResult->getBody();
|
$img_str = $curlResult->getBody();
|
||||||
$contType = $curlResult->getContentType();
|
$type = $curlResult->getContentType();
|
||||||
} else {
|
} else {
|
||||||
$img_str = '';
|
$img_str = '';
|
||||||
$contType = [];
|
$type = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = Images::getMimeTypeByData($img_str, $photo, $contType);
|
$type = Images::getMimeTypeByData($img_str, $photo, $type);
|
||||||
|
|
||||||
$Image = new Image($img_str, $type);
|
$Image = new Image($img_str, $type);
|
||||||
if ($Image->isValid()) {
|
if ($Image->isValid()) {
|
||||||
|
|
|
@ -245,7 +245,7 @@ class CurlResult implements IHTTPResult
|
||||||
public function getHeader($header)
|
public function getHeader($header)
|
||||||
{
|
{
|
||||||
if (empty($header)) {
|
if (empty($header)) {
|
||||||
return [];
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$header = strtolower(trim($header));
|
$header = strtolower(trim($header));
|
||||||
|
@ -256,7 +256,7 @@ class CurlResult implements IHTTPResult
|
||||||
return $headers[$header];
|
return $headers[$header];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@ -289,11 +289,7 @@ class CurlResult implements IHTTPResult
|
||||||
$parts = explode(':', $line);
|
$parts = explode(':', $line);
|
||||||
$headerfield = strtolower(trim(array_shift($parts)));
|
$headerfield = strtolower(trim(array_shift($parts)));
|
||||||
$headerdata = trim(implode(':', $parts));
|
$headerdata = trim(implode(':', $parts));
|
||||||
if (empty($this->header_fields[$headerfield])) {
|
$this->header_fields[$headerfield] = $headerdata;
|
||||||
$this->header_fields[$headerfield] = [$headerdata];
|
|
||||||
} elseif (!in_array($headerdata, $this->header_fields[$headerfield])) {
|
|
||||||
$this->header_fields[$headerfield][] = $headerdata;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->header_fields;
|
return $this->header_fields;
|
||||||
|
|
|
@ -19,7 +19,7 @@ interface IHTTPResult
|
||||||
/**
|
/**
|
||||||
* Returns the Content Type
|
* Returns the Content Type
|
||||||
*
|
*
|
||||||
* @return string[] the Content Types
|
* @return string the Content Type
|
||||||
*/
|
*/
|
||||||
public function getContentType();
|
public function getContentType();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ interface IHTTPResult
|
||||||
*
|
*
|
||||||
* @param string $header optional header field. Return all fields if empty
|
* @param string $header optional header field. Return all fields if empty
|
||||||
*
|
*
|
||||||
* @return string[] the headers or the specified content of the header variable
|
* @return string the headers or the specified content of the header variable
|
||||||
*/
|
*/
|
||||||
public function getHeader($header);
|
public function getHeader($header);
|
||||||
|
|
||||||
|
|
|
@ -429,7 +429,7 @@ class Probe
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it isn't a HTML file then exit
|
// If it isn't a HTML file then exit
|
||||||
if (!in_array('html', $curlResult->getContentType())) {
|
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -747,7 +747,7 @@ class OStatus
|
||||||
$xml = '';
|
$xml = '';
|
||||||
|
|
||||||
if ($curlResult->inHeader('Content-Type') &&
|
if ($curlResult->inHeader('Content-Type') &&
|
||||||
in_array('application/atom+xml', $curlResult->getHeader('Content-Type'))) {
|
stristr($curlResult->getHeader('Content-Type'), 'application/atom+xml')) {
|
||||||
$xml = $curlResult->getBody();
|
$xml = $curlResult->getBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -941,7 +941,7 @@ class OStatus
|
||||||
$xml = '';
|
$xml = '';
|
||||||
|
|
||||||
if ($curlResult->inHeader('Content-Type') &&
|
if ($curlResult->inHeader('Content-Type') &&
|
||||||
in_array('application/atom+xml', $curlResult->getHeader('Content-Type'))) {
|
stristr($curlResult->getHeader('Content-Type'), 'application/atom+xml')) {
|
||||||
Logger::log('Directly fetched XML for URI ' . $related_uri, Logger::DEBUG);
|
Logger::log('Directly fetched XML for URI ' . $related_uri, Logger::DEBUG);
|
||||||
$xml = $curlResult->getBody();
|
$xml = $curlResult->getBody();
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,23 +77,21 @@ class Images
|
||||||
*
|
*
|
||||||
* @param string $image_data Image data
|
* @param string $image_data Image data
|
||||||
* @param string $filename File name (for guessing the type via the extension)
|
* @param string $filename File name (for guessing the type via the extension)
|
||||||
* @param string[] $mimeTypes possible mime types
|
* @param string $mime default mime type
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function getMimeTypeByData(string $image_data, string $filename = '', array $mimeTypes = [])
|
public static function getMimeTypeByData(string $image_data, string $filename = '', string $mime = '')
|
||||||
{
|
{
|
||||||
foreach ($mimeTypes as $mimeType) {
|
if (substr($mime, 0, 6) == 'image/') {
|
||||||
if (substr($mimeType, 0, 6) == 'image/') {
|
Logger::info('Using default mime type', ['filename' => $filename, 'mime' => $mime]);
|
||||||
Logger::info('Using default mime type', ['filename' => $filename, 'mime' => $mimeTypes]);
|
return $mime;
|
||||||
return $mimeType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$image = @getimagesizefromstring($image_data);
|
$image = @getimagesizefromstring($image_data);
|
||||||
if (!empty($image['mime'])) {
|
if (!empty($image['mime'])) {
|
||||||
Logger::info('Mime type detected via data', ['filename' => $filename, 'default' => $mimeTypes, 'mime' => $image['mime']]);
|
Logger::info('Mime type detected via data', ['filename' => $filename, 'default' => $mime, 'mime' => $image['mime']]);
|
||||||
return $image['mime'];
|
return $image['mime'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ class ParseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it isn't a HTML file then exit
|
// If it isn't a HTML file then exit
|
||||||
if (!in_array('html', $curlResult->getContentType())) {
|
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
|
||||||
return $siteinfo;
|
return $siteinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,11 +198,9 @@ class ParseUrl
|
||||||
$charset = '';
|
$charset = '';
|
||||||
// Look for a charset, first in headers
|
// Look for a charset, first in headers
|
||||||
// Expected form: Content-Type: text/html; charset=ISO-8859-4
|
// Expected form: Content-Type: text/html; charset=ISO-8859-4
|
||||||
foreach ($curlResult->getContentType() as $type) {
|
if (preg_match('/charset=([a-z0-9-_.\/]+)/i', $curlResult->getContentType(), $matches)) {
|
||||||
if (preg_match('/charset=([a-z0-9-_.\/]+)/i', $type, $matches)) {
|
|
||||||
$charset = trim(trim(trim(array_pop($matches)), ';,'));
|
$charset = trim(trim(trim(array_pop($matches)), ';,'));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Then in body that gets precedence
|
// Then in body that gets precedence
|
||||||
// Expected forms:
|
// Expected forms:
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'http/2 200' => [''],
|
'http/2 200' => '',
|
||||||
'date' => ['Thu, 11 Oct 2018 18:43:54 GMT'],
|
'date' => 'Thu, 11 Oct 2018 18:43:54 GMT',
|
||||||
'content-type' => ['text/html; charset=utf-8'],
|
'content-type' => 'text/html; charset=utf-8',
|
||||||
'vary' => ['Accept-Encoding'],
|
'vary' => 'Accept-Encoding',
|
||||||
'server' => ['Mastodon'],
|
'server' => 'Mastodon',
|
||||||
'x-frame-options' => ['DENY', 'SAMEORIGIN'],
|
'x-frame-options' => 'SAMEORIGIN',
|
||||||
'x-content-type-options' => ['nosniff'],
|
'x-content-type-options' => 'nosniff',
|
||||||
'x-xss-protection' => ['1; mode=block'],
|
'x-xss-protection' => '1; mode=block',
|
||||||
'etag' => ['W/"706e6c48957e1d46ecf9d7597a7880af"'],
|
'etag' => 'W/"706e6c48957e1d46ecf9d7597a7880af"',
|
||||||
'cache-control' => ['max-age=0, private, must-revalidate'],
|
'cache-control' => 'max-age=0, private, must-revalidate',
|
||||||
'set-cookie' => ['_mastodon_session=v3kcy%2FW3aZYBBvZUohuwksEKwzYIyEUlEuJ1KqTAfWPKvVQq%2F4UuJ39zp621VyfpQNlvY46TL%2FYutzXowSLYQBNFCJcrEiF04aU0TdtHls9zynMiyeHhoVgCijOXWXNt9%2FCmpQ49RkNEujkv9NaJ0cum32MCVZKjE9%2BMKmLM%2F8ZygZeLBGJ7sg%3D%3D--QGIiU0%2FpXc3Aym8F--he2iRRPePOdtEs3z%2BufSXg%3D%3D; path=/; secure; HttpOnly'],
|
'set-cookie' => '_mastodon_session=v3kcy%2FW3aZYBBvZUohuwksEKwzYIyEUlEuJ1KqTAfWPKvVQq%2F4UuJ39zp621VyfpQNlvY46TL%2FYutzXowSLYQBNFCJcrEiF04aU0TdtHls9zynMiyeHhoVgCijOXWXNt9%2FCmpQ49RkNEujkv9NaJ0cum32MCVZKjE9%2BMKmLM%2F8ZygZeLBGJ7sg%3D%3D--QGIiU0%2FpXc3Aym8F--he2iRRPePOdtEs3z%2BufSXg%3D%3D; path=/; secure; HttpOnly',
|
||||||
'x-request-id' => ['a0c0b8e7-cd60-4efa-b79b-cf1b0d5a0784'],
|
'x-request-id' => 'a0c0b8e7-cd60-4efa-b79b-cf1b0d5a0784',
|
||||||
'x-runtime' => ['0.049566'],
|
'x-runtime' => '0.049566',
|
||||||
'strict-transport-security' => ['max-age=31536000; includeSubDomains; preload'],
|
'strict-transport-security' => 'max-age=31536000; includeSubDomains; preload',
|
||||||
'referrer-policy' => ['same-origin'],
|
'referrer-policy' => 'same-origin',
|
||||||
'content-security-policy' => ["frame-ancestors 'none'; script-src 'self'; object-src 'self'; img-src * data: blob:; media-src 'self' data:; font-src 'self' data: https://fonts.gstatic.com/; connect-src 'self' blob: wss://mastodonten.de"],
|
'content-security-policy' => "frame-ancestors 'none'; script-src 'self'; object-src 'self'; img-src * data: blob:; media-src 'self' data:; font-src 'self' data: https://fonts.gstatic.com/; connect-src 'self' blob: wss://mastodonten.de",
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'http/2 301' => [''],
|
'http/2 301' => '',
|
||||||
'date' => ['Thu, 11 Oct 2018 18:43:54 GMT'],
|
'date' => 'Thu, 11 Oct 2018 18:43:54 GMT',
|
||||||
'content-type' => ['text/html; charset=utf-8'],
|
'content-type' => 'text/html; charset=utf-8',
|
||||||
'vary' => ['Accept-Encoding'],
|
'vary' => 'Accept-Encoding',
|
||||||
'server' => ['Mastodon'],
|
'server' => 'Mastodon',
|
||||||
'location' => ['https://test.other/some/'],
|
'location' => 'https://test.other/some/',
|
||||||
'x-frame-options' => ['DENY', 'SAMEORIGIN'],
|
'x-frame-options' => 'SAMEORIGIN',
|
||||||
'x-content-type-options' => ['nosniff'],
|
'x-content-type-options' => 'nosniff',
|
||||||
'x-xss-protection' => ['1; mode=block'],
|
'x-xss-protection' => '1; mode=block',
|
||||||
'etag' => ['W/"706e6c48957e1d46ecf9d7597a7880af"'],
|
'etag' => 'W/"706e6c48957e1d46ecf9d7597a7880af"',
|
||||||
'cache-control' => ['max-age=0, private, must-revalidate'],
|
'cache-control' => 'max-age=0, private, must-revalidate',
|
||||||
'set-cookie' => ['_mastodon_session=v3kcy%2FW3aZYBBvZUohuwksEKwzYIyEUlEuJ1KqTAfWPKvVQq%2F4UuJ39zp621VyfpQNlvY46TL%2FYutzXowSLYQBNFCJcrEiF04aU0TdtHls9zynMiyeHhoVgCijOXWXNt9%2FCmpQ49RkNEujkv9NaJ0cum32MCVZKjE9%2BMKmLM%2F8ZygZeLBGJ7sg%3D%3D--QGIiU0%2FpXc3Aym8F--he2iRRPePOdtEs3z%2BufSXg%3D%3D; path=/; secure; HttpOnly'],
|
'set-cookie' => '_mastodon_session=v3kcy%2FW3aZYBBvZUohuwksEKwzYIyEUlEuJ1KqTAfWPKvVQq%2F4UuJ39zp621VyfpQNlvY46TL%2FYutzXowSLYQBNFCJcrEiF04aU0TdtHls9zynMiyeHhoVgCijOXWXNt9%2FCmpQ49RkNEujkv9NaJ0cum32MCVZKjE9%2BMKmLM%2F8ZygZeLBGJ7sg%3D%3D--QGIiU0%2FpXc3Aym8F--he2iRRPePOdtEs3z%2BufSXg%3D%3D; path=/; secure; HttpOnly',
|
||||||
'x-request-id' => ['a0c0b8e7-cd60-4efa-b79b-cf1b0d5a0784'],
|
'x-request-id' => 'a0c0b8e7-cd60-4efa-b79b-cf1b0d5a0784',
|
||||||
'x-runtime' => ['0.049566'],
|
'x-runtime' => '0.049566',
|
||||||
'strict-transport-security' => ['max-age=31536000; includeSubDomains; preload'],
|
'strict-transport-security' => 'max-age=31536000; includeSubDomains; preload',
|
||||||
'referrer-policy' => ['same-origin'],
|
'referrer-policy' => 'same-origin',
|
||||||
'content-security-policy' => ["frame-ancestors 'none'; script-src 'self'; object-src 'self'; img-src * data: blob:; media-src 'self' data:; font-src 'self' data: https://fonts.gstatic.com/; connect-src 'self' blob: wss://mastodonten.de"],
|
'content-security-policy' => "frame-ancestors 'none'; script-src 'self'; object-src 'self'; img-src * data: blob:; media-src 'self' data:; font-src 'self' data: https://fonts.gstatic.com/; connect-src 'self' blob: wss://mastodonten.de",
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue