Garbled output with port forwarding

Not sure if this is a codespaces problem or not.

I launch a webserver in the codespace at the end of a build script (compiling with emscripten). This is an HTTP server via emrun, I guess it is the built in python server. When i do this in codespaces i get garbled output in the terminal.

Web server root directory: /root/workspace/MySynthTest/MySynthTest/build-web
Now listening at - - [08/Jan/2021 15:38:42] code 400, message Bad request version ("á°\x96ä\x0fkÓ¶\x00®NR\x8e©+\x17é\x03\x12!x=3\x19ÿëu\xad¸\x00>\x13\x02\x13\x03\x13\x01À,À0\x00\x9f̨̩̪À+À/\x00\x9eÀ$À(\x00kÀ#À'\x00gÀ")
§.¬Ï Ì0.1 - - [08/Jan/2021 15:38:42] "2.{Ùà¶äïþ~Ñ3wÏ@ñ©Àfȧ
       á°äkÓ¶®NR©+é!x=3ÿëu­¸>À,À0©Ì¨ÌªÀ+À/$À(kÀ#À'gÀ" 400 - - - [08/Jan/2021 15:38:46] code 400, message Bad request version ('«\x83é\x8féE÷q\x92\x82¬;BdÙ\x7f\x15zJBaJpï') - - [08/Jan/2021 15:38:46] "2.0
C ß÷¢ëIn0á «ééE÷q¬;BdÙzJBaJpï" 400 -

I’m investigating how to launch an HTTPS server instead with an mkcert certificate, but I thought I would ask here incase this is a codespaces issue


Yes, it’s due to Codespaces. The port forwarding infrastructure is probing your app to see if it’s running HTTPS or just HTTP, so it tries to perform a TLS handshake to see if it accepts HTTPS. You app doesn’t support HTTPS (which is fine), but it does log the request, which appears malformed in the logs. You should be able to safely ignore that output for now.

We are considering ways to improve this detection where it won’t cause the malformed output in your app logs. One possible solution is to prefer HTTP instead of HTTPS, so we would check for that first, although that could have a similar issue for apps that only support HTTPS.

No matter whether your app serves content over HTTP or HTTPS, the port forwarding in a codespace is always transferred over an encrypted channel.

(1) Client (browser or VS Code desktop) --> (2) https connection to https://* --> (3) encrypted SSH tunnel to the codespace VM, which makes the request to your app running on localhost:port.

The HTTP/HTTPS probing is done so that the intermediate proxy layer in (2) knows which protocol to use for the request to (3) that is tunneled through the secure SSH tunnel.


Thanks for the info.

I need HTTPS anyway, so hopefully by modifying emrun to use an mkcert certificate i will clean up the terminal output too