Added file server

Added file server for no units URI paths.
Fixed a lot of bugs in parser and mainloop.
Added function Get_MIME_Type
This commit is contained in:
Doczom
2023-11-19 13:15:58 +05:00
committed by GitHub
parent 3d3fa69481
commit 6030a5f8fe
7 changed files with 613 additions and 53 deletions

View File

@@ -83,27 +83,108 @@ http_err_response:
db 13, 10
.size = $ - http_err_response
http_response_err_501:
db 'HTTP/1.1 '
db '501 ',13, 10
db 'Server: simple-httpd/0.0.1', 13, 10
db 'Content-length: 91', 13, 10
db 'Content-type: text/plain', 13, 10;
db 'Connection: close', 13, 10
db 13, 10
db 'Error parsing your request message. The version is not supported or another error.'
.size = $ - http_response_err_501
http_response_err_404:
db 'HTTP/1.1 '
db '404 ',13, 10
db 'Server: simple-httpd/0.0.1', 13, 10
db 'Content-length: 45', 13, 10
db 'Content-type: text/plain', 13, 10;
db 'Connection: close', 13, 10
db 13, 10
db 'The server could not find the requested page.'
.size = $ - http_response_err_404
http_response_options:
db 'HTTP/1.1 '
db '204 ',13, 10
db 'Server: simple-httpd/0.0.1', 13, 10
db 'Allow: OPTIONS, GET, POST', 13, 10
db 'Connection: close', 13, 10
db 13, 10
.size = $ - http_response_options
base_response:
label response at 0
response:
db 'HTTP/1.0 '
.code: db '000 ',13, 10
db 'Server: httpd(kolibri os)/0.0.1', 13, 10
.code = $ - response
db '000 ',13, 10
db 'Server: simple-httpd/0.0.1', 13, 10 ; httpd(kolibri os)/0.0.1, 13, 10
db 'Cache-Control: no-cache', 13, 10
db 'Content-Encoding: '
.content_encod: db 'identity', 13, 10
db 'Date: '
.date: db 'Sun, 30 Oct 2022 09:29:13 GMT',13, 10
.content_encod = $ - response
db 'identity', 13, 10
; db 'Date: '
;.date: db 'Sun, 30 Oct 2022 09:29:13 GMT',13, 10
db 'Content-length: '
.content_len: db ' ', 13, 10
;.content_len: db ' ', 13, 10
.content_len = $ - response
db '0000000000000000000000', 13, 10
db 'Content-type: '
.content_type: db ' ', 13, 10;
.content_type = $ - response
db ' ', 13, 10;
;'text/html; charset=utf-8'
.end_headers: ;нужно, когда базового заголовка не хватает
.connection db 'Connection: close', 13, 10
;.end_headers: ;нужно, когда базового заголовка не хватает
.connection = $ - response
db 'Connection: close', 13, 10
db 13, 10
.body: ; с этого оффсета уже писать данные
.body = $ - response ; с этого оффсета уже писать данные
; min HTTP request size
; "GET / HTTP/1.1" - 18 byte
min_http_size = 18
MIME_TYPES:
.html: db 'text/html',0
.css: db 'text/css',0
.js: db 'text/javascript',0
.txt: db 'text/plain',0
.json: db 'application/json',0
.pdf: db 'application/pdf',0
.png: db 'image/png',0
.mp3: db 'audio/mpeg',0
.mp4: db 'video/mp4',0
.other: db 'application/octet-stream',0 ; for unknow file - all file :)
MIME_FILE_FORMAT:
.html: db 5,'.html',0
.css: db 4,'.css',0
.js: db 3,'.js',0
.txt: db 4,'.txt',0
.pdf: db 4,'.pdf',0
.json: db 5,'.json',0
.png: db 4,'.png',0
.mp3: db 4,'.mp3',0
.mp4: db 4,'.mp4',0
STD_MIME_TYPE_ARR:
dd MIME_FILE_FORMAT.html, MIME_TYPES.html,\
MIME_FILE_FORMAT.css, MIME_TYPES.css,\
MIME_FILE_FORMAT.js, MIME_TYPES.js,\
MIME_FILE_FORMAT.txt, MIME_TYPES.txt,\
MIME_FILE_FORMAT.pdf, MIME_TYPES.pdf,\
MIME_FILE_FORMAT.json, MIME_TYPES.json,\
MIME_FILE_FORMAT.png, MIME_TYPES.png,\
MIME_FILE_FORMAT.mp3, MIME_TYPES.mp3,\
MIME_FILE_FORMAT.mp4, MIME_TYPES.mp4,\
0, MIME_TYPES.other
_DIV_10_: dd 10
_DIV_100_: dd 100
_DIV_1000_: dd 1000