http-server icon indicating copy to clipboard operation
http-server copied to clipboard

HTTP 400 response with body "URI Error: URI malformed" when requesting an URL with a ISO-8859-1 encoding

Open daniel-a-melo opened this issue 9 years ago • 2 comments

When requesting an URL with ISO-8859-1 enconding the server fails with HTTP 400 (bad request) and the following body:

URIError: URI malformed

URL : /index.html?param=%DANICO

%DANICO is ÚNICO URL enconded using ISO-8859-1

daniel-a-melo avatar Mar 28 '16 17:03 daniel-a-melo

ecstatic, the web server under the hood of http-server, uses decodeURI, which decodes characters by their UTF-8 sequence, not by ISO-8859-1.

Weird stuff I noticed:

  • I get GET /U%CC%81NICO/ in the logs when requesting /ÚNICO in my browser.
  • encodeURIComponent('ÚNICO') gives me %C3%9ANICO.

derhuerst avatar Mar 28 '16 18:03 derhuerst

Since this issue was opened, we've internalized what ecstatic provided and removed the dependency, so we have more control over this. However, I'm not sure how to approach this, would we want some way to detect or configure what URL encoding to use? Or maybe if UTF-8 decoding fails, we try ISO-8859-1 and see if that works?

thornjad avatar Oct 15 '21 16:10 thornjad