0

我正在尝试使用 lwIP 在我的 STM32 上运行 SSI 页面。当我打开一个 .html 页面时,一切都显示得很好。但是 .shtml 页面不会被渲染,只有源代码可见。

这篇文章引导我使用 wget 查找 mimetype:

$ wget http://192.168.15.12/index.html
--2021-12-23 22:32:10--  http://192.168.15.12/index.html
Connecting to 192.168.15.12:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’

index.html.1            [ <=>                ]   1,92K  --.-KB/s    in 0,001s  

2021-12-23 22:32:10 (3,29 MB/s) - ‘index.html’ saved [1971]

$ wget http://192.168.15.12/monitor.shtml
--2021-12-23 22:32:21--  http://192.168.15.12/monitor.shtml
Connecting to 192.168.15.12:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: ‘monitor.shtml’

monitor.shtml.1         [ <=>                ]   1,92K  --.-KB/s    in 0,001s  

2021-12-23 22:32:21 (2,03 MB/s) - ‘monitor.shtml’ saved [1965]

看来,shtml 的 mimetype 设置错误(text/plain而不是text/html shtml?)。

有谁知道如何纠正这个?


将元添加到 HTML 头部没有帮助:

<meta http-equiv="Content-Type" content="text/html shtml; charset=utf-8">

元内容类型似乎被忽略了......

4

1 回答 1

0

好的 - 我找到了。mimetype 由 Perl 脚本 makefsdata 设置。shtml 文件结尾没有规则。所以我将规则添加到标题中:

    open(HEADER, "> /tmp/header") || die $!;
    if($file =~ /404/) {
    print(HEADER "HTTP/1.0 404 File not found\r\n");
    } else {
    print(HEADER "HTTP/1.0 200 OK\r\n");
    }
    print(HEADER "Server: lwIP/pre-0.6 (http://www.sics.se/~adam/lwip/)\r\n");
    if($file =~ /\.html$/) {
    print(HEADER "Content-type: text/html\r\n");
    } elsif($file =~ /\.shtml$/) {
    print(HEADER "Content-type: text/html shtml\r\n");
    } elsif($file =~ /\.gif$/) {
    print(HEADER "Content-type: image/gif\r\n");
    } elsif($file =~ /\.png$/) {
    print(HEADER "Content-type: image/png\r\n");
    } elsif($file =~ /\.jpg$/) {
    print(HEADER "Content-type: image/jpeg\r\n");
    } elsif($file =~ /\.class$/) {
    print(HEADER "Content-type: application/octet-stream\r\n");
    } elsif($file =~ /\.ram$/) {
    print(HEADER "Content-type: audio/x-pn-realaudio\r\n");    
    } else {
    print(HEADER "Content-type: text/plain\r\n");
    }
    print(HEADER "\r\n");
    close(HEADER);

现在它起作用了!


https://lists.gnu.org/archive/html/lwip-devel/2021-12/msg00029.html

于 2021-12-23T23:34:26.880 回答