Skip to content

Commit 52852a3

Browse files
committed
add mimeTypes in server
1 parent a8b6671 commit 52852a3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Ubiquity/servers/swoole/SwooleServer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Swoole\Http\Request;
66
use Swoole\Http\Response;
77
use Ubiquity\utils\http\foundation\SwooleHttp;
8+
use Ubiquity\utils\base\MimeType;
89
use Swoole\Process;
910

1011
class SwooleServer {
@@ -165,11 +166,13 @@ protected function handle(Request $request, Response $response) {
165166
if ($uriInfos['isAction']) {
166167
$request->get['c'] = $uri;
167168
} else {
168-
$response->header('Content-Type', $request->header['accept'] ?? 'text/html; charset=utf-8');
169169
if ($uriInfos['file']) {
170+
$mime = MimeType::getFileMimeType(\realpath($uri));
171+
$response->header('Content-Type', $mime . '; charset=utf-8');
170172
$response->end(\file_get_contents($this->basedir . '/../' . $uri));
171173
} else {
172174
$response->status(404);
175+
$response->header('Content-Type', 'text/plain; charset=utf-8');
173176
$response->end($uri . ' not found!');
174177
}
175178
return;

0 commit comments

Comments
 (0)