dukus / digiCamControl

DSLR camera remote control open source software
http://digicamcontrol.com/
Other
675 stars 226 forks source link

Duplicated Content-Length header on executing SLC via webserver #324

Open matheusmb opened 5 years ago

matheusmb commented 5 years ago

Hi, I found a bug in which the WebServer is sending a duplicated Content-Length header. I was trying to use Python requests lib and it was blocking the program execution. The requested URL was "http://127.0.0.1:5513/?slc=get&param1=lastcaptured&param2"

Here is the Headers dict that I'm receiving:

{'connection': 'Keep-Alive',
 'content-length': '12, 12',
 'content-type': 'text/html;charset=utf-8',
 'x-powered-by': 'Griffin.Networking (http://github.com/jgauffin/griffin.networking)'}

Pythons urllib doesn`t know how to deal with '12, 12'content-length and blocks the program flow (probably it's waiting to receive infinite bytes)

I did the following workaround:

    def execute(self, params):
        call_url = '{}/?{}'.format(DIGICAM_URL, params)
        stream = urlopen(call_url, timeout=2)

        # Digicam control has a bug in which sends duplicated Content-Length
        # Urllib doesn`t know how to deal with this size, and blocks the program flow
        content_length = stream.headers.getheader('Content-Length') # It may return '12, 12'
        real_content_length = int(content_length.split(',')[0])

        content = stream.read(real_content_length)
        stream.close()

        return content