STM32 和 lwIP - SHTML 页面未呈现 - 而是显示源代码
STM32 & lwIP - SHTML page not rendering - source code displayed instead
我正在尝试使用 lwIP 在我的 STM32 上获取 SSI 页面 运行。当我打开 .html 页面时,所有内容都显示正常。但是 .shtml 页面不会被渲染,只有源代码可见。
这 post 引导我使用 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 head 没有帮助:
<meta http-equiv="Content-Type" content="text/html shtml; charset=utf-8">
元内容类型似乎被忽略了...
好的 - 我找到了。 mimetype 由 Perl 脚本 makefsdata 设置。 shtml 文件结尾没有规则。所以我将规则添加到 header:
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
我正在尝试使用 lwIP 在我的 STM32 上获取 SSI 页面 运行。当我打开 .html 页面时,所有内容都显示正常。但是 .shtml 页面不会被渲染,只有源代码可见。
这 post 引导我使用 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 head 没有帮助:
<meta http-equiv="Content-Type" content="text/html shtml; charset=utf-8">
元内容类型似乎被忽略了...
好的 - 我找到了。 mimetype 由 Perl 脚本 makefsdata 设置。 shtml 文件结尾没有规则。所以我将规则添加到 header:
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