3

Due to a bug in chrome (https://code.google.com/p/chromium/issues/detail?id=439832) I want to serve a file through netcat instead of loading it directly. But, when I try to simply do nc -l -p 8000 < /tmp/file.mhtml and load http://localhost:8000 in Chrome, I get the text of the file instead of it being rendered as HTML. The file has a Content-Type header, So I expect it to be served:

From: <Saved by WebKit>
Subject: Foo Bar
Date: Fri, 22 Jan 2015 06:44:35 -0000
MIME-Version: 1.0
Content-Type: multipart/related;
    type="text/html";
    boundary="----=_NextPart_000_0B03_4EE56298.243AD9A7"

------=_NextPart_000_0B03_4EE56298.243AD9A7
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
Content-Location: https://example.com/foo/bar?q=4
IttayD
  • 28,271
  • 28
  • 124
  • 178
  • Can you check what headers Chrome picked up by visiting the Developer Console? Are the headers rendered in plain text as well? Does your file have HTTP/1.1 200 OK as the first line for example? – soulseekah Jan 28 '15 at 00:32
  • There are only request headers, no response headers – IttayD Feb 03 '15 at 10:18
  • You should add the HTTP preamble then (directly to the file for example), so Chrome can read them correctly. At least add `HTTP/1.1 200 OK` at the top of the file. – soulseekah Feb 03 '15 at 13:44
  • I did. Chrome still doesn't show any response headers – IttayD Feb 04 '15 at 14:25

2 Answers2

2

Using netcat you're serving an MHT file directly over TCP through netcat, instead of over HTTP. Chrome does not know how to deal with that since it does not seem to have support for MHTML.

Hans Z.
  • 50,496
  • 12
  • 102
  • 115
  • 1
    But that's like opening an HTML file from disk; it does not mean that you can serve that HTML file over plain TCP. – Hans Z. Feb 03 '15 at 11:54
0

You could add a valid HTTP response:

while [ $? == 0 ]; do nc -l -p 8000 -e 'printf "HTTP/1.1 200 OK\n\n"; cat /tmp/file.mhtml'; done
Eun
  • 4,146
  • 5
  • 30
  • 51