Closed sanchosk closed 2 years ago
This fix introduced a new bug as "r = cl.recv(1024)" may also contain the referer with the previous url. So toggling the LED is now not possible in a reliable way. See the example below from my experience:
Client connected from ('192.168.5.107', 51054) b'GET /%22?led=on\%22 HTTP/1.1\r\nHost: 192.168.5.155\r\nConnection: keep-alive\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9\r\nReferer: http://192.168.5.155/%22?led=off\%22\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9,nl;q=0.8\r\n\r\n' led_on = 10 led_off = 434 LED ON LED OFF
the condition ==10 is only valid for specific length of IP address. If the URL is shorter/longer, the find will result in different number, failing the condition. Using the -1 will fix this issue.