Skip to content

show Garbled message when Content-Type doesn't have charset part #627

@hh-in-zhuzhou

Description

@hh-in-zhuzhou

many of website's HTTP header's Content-Type part does not have Charset part, just like:

Content-Type: text/html

then shows garbled message in terminal/iTerm2 in macOS 10.13 when the html contains Chinese Character which encode with utf8 (which shows OK with curl), but when I change the header like this:

Content-Type: text/html; charset=utf-8

then OK

the garbled messge is below in body>h1

$ http --debug dev1.cn/test.html
HTTPie 0.9.9
Requests 2.12.3
Pygments 2.1.3
Python 3.6.3 (default, Oct  4 2017, 06:09:15)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
/usr/local/Cellar/httpie/0.9.9/libexec/bin/python3.6
Darwin 17.0.0

<Environment {
    "colors": 256,
    "config": {
        "__meta__": {
            "about": "HTTPie configuration file",
            "help": "https://httpie.org/docs#config",
            "httpie": "0.9.9"
        },
        "default_options": "[]"
    },
    "config_dir": "/Users/hh/.httpie",
    "is_windows": false,
    "stderr": "<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>",
    "stderr_isatty": true,
    "stdin": "<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>",
    "stdin_encoding": "UTF-8",
    "stdin_isatty": true,
    "stdout": "<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>",
    "stdout_encoding": "UTF-8",
    "stdout_isatty": true
}>

>>> requests.request(**{
    "allow_redirects": false,
    "auth": "None",
    "cert": "None",
    "data": {},
    "files": {},
    "headers": {
        "User-Agent": "HTTPie/0.9.9"
    },
    "method": "get",
    "params": {},
    "proxies": {},
    "stream": true,
    "timeout": 30,
    "url": "http://dev1.cn/test.html",
    "verify": true
})

HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html
Date: Sun, 05 Nov 2017 15:23:00 GMT
ETag: W/"59ff2cc9-a7"
Last-Modified: Sun, 05 Nov 2017 15:22:49 GMT
Server: nginx/1.10.3 (Ubuntu)
Transfer-Encoding: chunked

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <h1>你好���</h1>
    </body>
</html>

the garbled message disturbed me very much, which not exists in curl , but I like httpie more, can you improve it ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions