| 413 | //#endif |
| 414 | |
| 415 | static size_t prepare_header(char *buffer, const char *param, u8 is_binary) |
| 416 | { |
| 417 | if(!buffer || !param) return 0; |
| 418 | |
| 419 | bool set_base_path = false; |
| 420 | |
| 421 | size_t slen = sprintf(buffer, "HTTP/1.1 200 OK\r\n" |
| 422 | "%s" |
| 423 | "Content-Type: ", |
| 424 | webman_config->bind ? "" : // disallow CORS if bind (remote access to FTP/WWW services) is disabled |
| 425 | "Access-Control-Allow-Origin: *\r\n"); // default: allow CORS (Cross-Origin Resource Sharing) |
| 426 | |
| 427 | t_string *header, mimetype; _set(&mimetype, buffer, slen); header = &mimetype; |
| 428 | |
| 429 | // get mime type |
| 430 | if(is_binary == BINARY_FILE) |
| 431 | { |
| 432 | const char *ext = get_ext(param); |
| 433 | |
| 434 | if(_IS(ext, ".png")) |
| 435 | _concat2(&mimetype, "image/", "png"); |
| 436 | else |
| 437 | if(_IS(ext, ".jpg") || _IS(ext, ".jpeg") || IS(ext, ".STH")) |
| 438 | _concat2(&mimetype, "image/", "jpeg"); |
| 439 | else |
| 440 | if(_IS(ext, ".htm") || _IS(ext, ".html") || _IS(ext, ".shtm")) |
| 441 | {_concat2(&mimetype, "text/", "html;charset=UTF-8"); set_base_path = true;} |
| 442 | else |
| 443 | if(_IS(ext + 1, ".js")) |
| 444 | _concat2(&mimetype, "text/", "javascript"); |
| 445 | else |
| 446 | if(_IS(ext, ".css")) |
| 447 | _concat2(&mimetype, "text/", "css"); |
| 448 | else |
| 449 | if(_IS(ext, ".txt") || _IS(ext, ".log") || _IS(ext, ".ini") || _IS(ext, ".cfg") || IS(ext, ".HIP") || IS(ext, ".HIS") || IS(ext, ".HIP") || IS(ext, ".CNF")) |
| 450 | _concat2(&mimetype, "text/", "plain;charset=UTF-8"); |
| 451 | else |
| 452 | if(_IS(ext, ".svg")) |
| 453 | _concat2(&mimetype, "image/", "svg+xml"); |
| 454 | #ifndef LITE_EDITION |
| 455 | else |
| 456 | if(_IS(ext, ".gif")) |
| 457 | _concat2(&mimetype, "image/", "gif"); |
| 458 | else |
| 459 | if(_IS(ext, ".bmp")) |
| 460 | _concat2(&mimetype, "image/", "bmp"); |
| 461 | else |
| 462 | if(_IS(ext, ".tif")) |
| 463 | _concat2(&mimetype, "image/", "tiff"); |
| 464 | else |
| 465 | if(_IS(ext, ".avi")) |
| 466 | _concat2(&mimetype, "video/", "x-msvideo"); |
| 467 | else |
| 468 | if(_IS(ext, ".mp4") || IS(ext, ".MTH")) |
| 469 | _concat2(&mimetype, "video/", "mp4"); |
| 470 | else |
| 471 | if(_IS(ext, ".mkv")) |
| 472 | _concat2(&mimetype, "video/", "x-matroska"); |