Bad HTTP parsed: 400 Illegal character 0x20 for HttpReceiverOverHTTP

Hello!
I’ve a “China IP camera” and I can get snapshot by WEB (browser) or WGET:

#wget http://192.168.1.3/cgi-bin/getsnapshot.cgi
 ..
2018-03-17 14:42:05 (998 KB/s) - "getsnapshot.cgi" saved [83352/83352]

# file getsnapshot.cgi
getsnapshot.cgi: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 720x576, frames 3

But this is the result with OH 1.x or 2.x.

Text label="In" icon="corridor" {
    Image url="http://192.168.1.3/cgi-bin/getsnapshot.cgi" refresh=10000
}

2018-03-17 14:37:06.415 [WARN ] [org.eclipse.jetty.http.HttpParser   ] - Illegal character 0x20 in state=HEADER_IN_NAME for buffer DirectByteBuffer@40ea8a[p=26,l=239,c=16384,r=213]={HTTP/1.0 200 OK\r\nHTTP/1.1 <<<200 OK\r\nServer: t...ngth: 83042\r\n\r\n>>>^\xFa\xE9\xB8i\xE4#>\xA0\x0c\xFf\x00:\xE0\xD83&...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00}
2018-03-17 14:37:06.421 [WARN ] [org.eclipse.jetty.http.HttpParser   ] - bad HTTP parsed: 400 Illegal character 0x20 for HttpReceiverOverHTTP@871172(rsp=BEGIN,failure=null)[HttpParser{s=HEADER_IN_NAME,0 of 0}]
2018-03-17 14:37:06.439 [WARN ] [.internal.proxy.BlockingProxyServlet] - Proxy servlet failed to stream content: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: bad response on HttpConnectionOverHTTP@b881fa(l:/192.168.1.2:37866 <-> r:/192.168.1.3:80,closed=false)[HttpChannelOverHTTP@1ba1b49(exchange=HttpExchange@85a90e req=TERMINATE
D/null@null res=PENDING/null@null)[send=HttpSenderOverHTTP@133ded(req=QUEUED,snd=COMPLETED,failure=null)[HttpGenerator@c6d104{s=START}],recv=HttpReceiverOverHTTP@871172(rsp=BEGIN,failure=null)[HttpParser{s=CLOSE,0 of 0}]]]

Other China IP camera work correctly.

How to fix this?

Regards

Your wget IP is 192.168.1.3
Your Image url IP is 192.168.2.243

Maybe that’s the problem?

Thank you, but it is only a wrong copy/paste as example.
(fixed now the post)

The issue is present!

What browser are you using?
What do you get when you put http://192.168.1.3/cgi-bin/getsnapshot.cgi in the browser?

Ok so I re-read your post at the beginning you say that you get the image in the browser.
Hoiw does the other camera work?
Does it point to a cgi file as well?

cgi files are website scripts not images.
wget and the browser will download the image generated by the cgi script but not the sitemap “binding”
An alternative way to do this would be to get the exec binding to execute the wget command and store the image in your /conf/html folder and then point the sitemap image to that file.

This is the full sniff with a browser:

GET /cgi-bin/getsnapshot.cgi HTTP/1.1
Host: 192.168.1.3
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1


HTTP/1.0 200 OK
HTTP/1.1 200 OK
Server: thttpd/2.25b 29dec2003
Date: Sat, 17 Mar 2018 17:49:27 GMT
Last-Modified: Sat, 17 Mar 2018 17:49:27 GMT
Content-Type: image/jpeg
Accept-Ranges: bytes
Connection: close
Content-Length: 74033

......JFIF....................................
.....
...
..
...
................................	..	.
.
.........................................................	..	.
.
........................................................@....".....................................	
.................}........!1A..Qa."q.2....#B...R..$3br.	
.....%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz...................................................................................................	
.................w.......!1..AQ.aq."2...B....	#3R..br.
.$4.%.....&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz..........................................................................................?....n.,p:.j........*.\.........8$d.Uk.+..'.4.<.....T..K;}.z.+...@.%l...[Z..PC.r8..k7......M...}.=q....t.9.:.*]...fyf..H..QrY.....kDYlD;.8. ...=....-Q.....D.....L....U..6..i.I!

[...]

The content-type is right (image/jpeg)

Content-Type: image/jpeg

The problem could be the double HTTP/1.x reply:

HTTP/1.0 200 OK
HTTP/1.1 200 OK
Server: thttpd/2.25b 29dec2003

This is the log from OH 1.x or 2.x:

Illegal character 0x20 in state=HEADER_IN_NAME for buffer
DirectByteBuffer@40ea8a[p=26,l=239,c=16384,r=213]=
{HTTP/1.0 200 OK\r\nHTTP/1.1 <<<200 OK\r\nServer: t...ngth: 83042\r\n\r\n>>>  <- !!!
^\xFa\xE9\xB8i\xE4#>\xA0\x0c\xFf\x00:\xE0\xD83&...
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00

Is it possible to fix this with a “reverse proxy” or other tricks ? (without download)

Regards

I’ve tested this now:

    location /get-camera.jpg {
            proxy_pass                            http://192.168.1.3/cgi-bin/getsnapshot.cgi;
            proxy_buffering                       off;
            proxy_set_header Host                 $http_host;
            proxy_set_header X-Real-IP            $remote_addr;
            proxy_set_header X-Forwarded-For      $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto    $scheme;
    }

Text label="In" icon="corridor" {
    Image url="http://localhost/get-camera.jpg" refresh=10000
}

This reverse proxy work correctly!

…but I’m interesting to know if it’s possible to fix the org.eclipse.jetty.http.HttpParser

It looks like the sitemap image parser doesn’t like the .cgi extension
and only accepts image file extensions. maybe raise an issue on github

Or your can look at the source code yourself and submit a pull request

Hi, did you find a solution or workaround for this issue?
I am having the same problem with this image item:

Image url="http://172.26.0.61:81/snapshot.cgi?user=xxxx&pwd=xxxxx&res=1" refresh=5000

and my log file is continuously being filled with many lines like these ones:

20:33:08.338 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - Illegal character 0x20 in state=HEADER_IN_NAME for buffer DirectByteBuffer@693b54[p=39,l=131,c=16384,r=92]={HTTP/1.1 200 OK\r\n... GoaHead\r\nTue, <<<12 Jun 2012 01:56...ection: close\n\n>>>\xFf\xD8\xFf\xE0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
20:33:08.657 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - bad HTTP parsed: 400 Illegal character 0x20 for HttpReceiverOverHTTP@1ab97ee(rsp=HEADER,failure=null)[HttpParser{s=HEADER_IN_NAME,0 of 0}]
20:33:09.475 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - Illegal character 0x20 in state=HEADER_IN_NAME for buffer DirectByteBuffer@693b54[p=39,l=131,c=16384,r=92]={HTTP/1.1 200 OK\r\n... GoaHead\r\nTue, <<<12 Jun 2012 01:56...ection: close\n\n>>>\xFf\xD8\xFf\xE0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
20:33:09.795 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - bad HTTP parsed: 400 Illegal character 0x20 for HttpReceiverOverHTTP@1877fa4(rsp=HEADER,failure=null)[HttpParser{s=HEADER_IN_NAME,0 of 0}]
20:33:10.658 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - Illegal character 0x20 in state=HEADER_IN_NAME for buffer DirectByteBuffer@693b54[p=39,l=8819,c=16384,r=8780]={HTTP/1.1 200 OK\r\n... GoaHead\r\nTue, <<<12 Jun 2012 01:56...S\xA8\xD3sVw1b\x83h\x1c\x1e*\xEc\x1f>>>93\xCb<\x80\xFa\xE6\xE6c_\xC1>\xE7-u...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
20:33:10.953 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - bad HTTP parsed: 400 Illegal character 0x20 for HttpReceiverOverHTTP@5a7e14(rsp=HEADER,failure=null)[HttpParser{s=HEADER_IN_NAME,0 of 0}]
20:33:11.626 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - Illegal character 0x20 in state=HEADER_IN_NAME for buffer DirectByteBuffer@693b54[p=39,l=4475,c=16384,r=4436]={HTTP/1.1 200 OK\r\n... GoaHead\r\nTue, <<<12 Jun 2012 01:56...\x1e\x80\xE3\xDa\xBeM\xFf\x00\x82|^\xC9\xE2o\x0e>>>\xAf]\xD4~&\xCf\xF0\xDbR\xF1W\x86\xF5\xFb\xA7uM...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
20:33:11.934 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - bad HTTP parsed: 400 Illegal character 0x20 for HttpReceiverOverHTTP@c7532c(rsp=HEADER,failure=null)[HttpParser{s=HEADER_IN_NAME,0 of 0}]
20:33:12.605 [WARN ] [org.eclipse.jetty.http.HttpParser    ] - Illegal character 0x20 in state=HEADER_IN_NAME for buffer DirectByteBuffer@693b54[p=39,l=131,c=16384,r=92]={HTTP/1.1 200 OK\r\n... GoaHead\r\nTue, <<<12 Jun 2012 01:56...ection: close\n\n>>>\xFf\xD8\xFf\xE0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00...\x00\x00\x00\x00    \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
..........................................................
...........................................................

The only way to avoid these errors from the sitemap is to remove the image item.

If you have found a solution I will appreciate you sharing it. I have done quite a research and have not found a way to solve it.

Thanks :wink:

This post describes the cause.

You should pull a debug log and examine the headers to determine which ones are non-compliant.

Hello

this is the workaround!

Here

Sim, Namraccr… thanks for your quick reply and excuse me for bothering you.
My problem is that I don’t have enough knowledge to understand the workaround suggested by Sim.
Where should I place the following code?

    location /get-camera.jpg {
            proxy_pass                            http://192.168.1.3/cgi-bin/getsnapshot.cgi;
            proxy_buffering                       off;
            proxy_set_header Host                 $http_host;
            proxy_set_header X-Real-IP            $remote_addr;
            proxy_set_header X-Forwarded-For      $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto    $scheme;
    }

Is this a script?
Thanks for your help,
Matt

Oh, sorry!
This is the NGINX configuration.
You need to install it and configure a “reverse proxy” with these settings (adjusting “proxy_pass”)
Bye

Aaaah! Ok, thanks Sim.
And don’t say sorry… I very much appreciate your time to provide me with indications.

I have done some research to eventually find that NGIX is already installed in the Synology NAS where my instance of openHAB is already running.

There are three .conf files under /etc/nginx (see attached nginx.txt (9.5 KB), proxy.txt (277 Bytes) and fastcgi.txt (1.1 KB) - extension changed from .conf to .txt so as to be able to upload them). I assume that the one I need to modify is ngix.conf (it is the only one where I have seen something like “location /”).
Configuration seems to be in individual server {….} blocks depending on the listening port and I can see config blocks for ports 5000, 5001, 80 and 443. All the blocks start with

server {
    listen [port number] default_server;
    listen [::]:[port number] default_server;
    server_name _;
    ………...
}

According to the following image item definition required to retrieve the current image from my ipcam:

Image url=“http://172.26.0.61:81/snapshot.cgi?user=xxxx&pwd=xxxxx” refresh=5000

which turns to be an url similar to the one where Sim found the same issue I found:

Image url=“http://192.168.1.3/cgi-bin/getsnapshot.cgi” refresh=10000

and taking into consideration the solution found by Sim I assume that I have to define a new block for port 81 that should look as follows:

server {
    listen 81 default_server;
    listen [::]:81 default_server;
    server_name _;

    location /get-camera.jpg {
    proxy_pass                          http://172.26.0.61:81/snapshot.cgi?user=xxxx&pwd=xxxxx;
    proxy_buffering                     off;
    proxy_set_header Host               $http_host;
    proxy_set_header X-Real-IP         	$remote_addr;
    proxy_set_header X-Forwarded-For	$proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto	$scheme;
}

Will you pls let me know if
a) ngix.conf is the config file where that I have to modify and
b) if this configuration will work or should I include additional lines?

Thanks a lot for your time!

Hello!
the configuration appears to be correct…
You can change the “/etc/nginx/sites-available/default” and left the nginx.conf standard.
Have you tested it?

Thanks Sim!
I have a rough idea of what I have to do but I don’t feel comfortable with my knowledge in regards to how to do it. That’s why I was waiting for your confirmation to ensure that this approach was correct.
I don’t have a "/etc/nginx/sites-available/default” to apply this modification. Instead there is a “nginx.conf.default” whose contents seem to be quite similar (nginx.conf.default.txt (3.4 KB)
without .txt). I have tried to apply this modification but I can’t because of an issue with permissions. I will investigate and find a way to do it. I will let you know.
Thanks a lot :wink: