Reference comments
This commit is contained in:
parent
d0ec102c53
commit
45ad0f6bdf
3 changed files with 53 additions and 14 deletions
|
@ -49,7 +49,7 @@ $avatarCallback = function (string $type, string $code, int $width, int $height,
|
|||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
|
||||
->setContentType('image/png')
|
||||
->file($data, 'image/png')
|
||||
->send($data)
|
||||
;
|
||||
unset($image);
|
||||
};
|
||||
|
@ -156,7 +156,7 @@ App::get('/v1/avatars/image')
|
|||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
|
||||
->setContentType('image/png')
|
||||
->file($data, 'image/png')
|
||||
->send($data)
|
||||
;
|
||||
unset($image);
|
||||
});
|
||||
|
@ -269,7 +269,7 @@ App::get('/v1/avatars/favicon')
|
|||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
|
||||
->setContentType('image/x-icon')
|
||||
->file($data, 'image/x-icon')
|
||||
->send($data)
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,7 @@ App::get('/v1/avatars/favicon')
|
|||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
|
||||
->setContentType('image/png')
|
||||
->file($data, 'image/png')
|
||||
->send($data)
|
||||
;
|
||||
unset($image);
|
||||
});
|
||||
|
@ -329,7 +329,7 @@ App::get('/v1/avatars/qr')
|
|||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache
|
||||
->setContentType('image/png')
|
||||
->file($image->output('png', 9), 'image/png')
|
||||
->send($image->output('png', 9))
|
||||
;
|
||||
});
|
||||
|
||||
|
@ -411,6 +411,6 @@ App::get('/v1/avatars/initials')
|
|||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache
|
||||
->setContentType('image/png')
|
||||
->file($image->getImageBlob(), 'image/png')
|
||||
->send($image->getImageBlob())
|
||||
;
|
||||
});
|
||||
|
|
|
@ -961,7 +961,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
|
|||
$response
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
|
||||
->setContentType($contentType)
|
||||
->file($data, $contentType)
|
||||
->send($data)
|
||||
;
|
||||
unset($image);
|
||||
});
|
||||
|
|
|
@ -447,23 +447,62 @@ class Response extends SwooleResponse
|
|||
|
||||
|
||||
/**
|
||||
* Set $payload for cache usage and sending file HTTP response.
|
||||
* Output response
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $contentType
|
||||
* Generate HTTP response output including the response header (+cookies) and body and prints them.
|
||||
*
|
||||
* @param string $body
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function file(string $data, string $contentType): void
|
||||
public function send(string $body = ''): void
|
||||
{
|
||||
if ($this->sent) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->sent = true;
|
||||
|
||||
$this->addHeader('X-Debug-Speed', (string)(\microtime(true) - $this->startTime));
|
||||
|
||||
$this->payload = [
|
||||
'content-type' => $contentType,
|
||||
'payload' => $data
|
||||
'content-type' => $this->getContentType(),
|
||||
'payload' => $body
|
||||
];
|
||||
|
||||
$this->send($data);
|
||||
$this
|
||||
->appendCookies()
|
||||
->appendHeaders()
|
||||
;
|
||||
|
||||
if (!$this->disablePayload) {
|
||||
$length = strlen($body);
|
||||
|
||||
$this->size = $this->size + strlen(implode("\n", $this->headers)) + $length;
|
||||
|
||||
if (
|
||||
array_key_exists(
|
||||
$this->contentType,
|
||||
$this->compressed
|
||||
) && ($length <= self::CHUNK_SIZE)
|
||||
) { // Dont compress with GZIP / Brotli if header is not listed and size is bigger than 2mb
|
||||
$this->end($body);
|
||||
} else {
|
||||
for ($i = 0; $i < ceil($length / self::CHUNK_SIZE); $i++) {
|
||||
$this->write(substr($body, ($i * self::CHUNK_SIZE), min(self::CHUNK_SIZE, $length - ($i * self::CHUNK_SIZE))));
|
||||
}
|
||||
|
||||
$this->end();
|
||||
}
|
||||
|
||||
$this->disablePayload();
|
||||
} else {
|
||||
$this->end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* YAML
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue