Search code examples
stm32lwipshtml

STM32 & lwIP - SHTML page not rendering - source code displayed instead


I'm trying to get an SSI page running on my STM32 using lwIP. When I open a .html page all is displayed fine. But .shtml pages will not be rendered and only the source code becomes visible.

This post leads me to look for the mimetype using wget:

$ 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]

It seems, that the mimetype is set wrong for shtml (text/plain instead text/html shtml?).

Does anyone know how to correct this?


Adding meta to HTML head does not help:

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

The meta content type seems to be ignored...


Solution

  • Ok - I found it. The mimetype was set by the Perl script makefsdata. There was no rule for shtml file endings. So I added the rule to the 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);
    

    Now it works!


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