Chrome версии 70.0.3538.102
Вот код моего простого http-сервера (на python)
from socket import *
import sys
server_socket = socket(AF_INET, SOCK_STREAM)
server_socket.bind(('localhost', 8080))
server_socket.listen(5)
print('Starting up http-server, serving ./')
print('Available on:')
print(' http://localhost:8080')
print('Hit CTRL-BREAK to stop the server')
while True:
connection_socket, address = server_socket.accept()
print()
print('Connected by: ', address[0] + ':' + str(address[1]))
try:
message = connection_socket.recv(1024)
filename = message.split()[1]
print('Filename to get: ', filename[1:].decode())
f = open(filename[1:], 'rb')
output_data = f.read()
connection_socket.send('HTTP/1.1 200 OK\r\n\r\n'.encode())
connection_socket.send(output_data)
connection_socket.send('\r\n'.encode())
connection_socket.close()
except IOError:
connection_socket.send('HTTP/1.1 404 Not Found\r\n\r\n'.encode())
connection_socket.send('404 Not Found'.encode())
connection_socket.send('\r\n'.encode())
connection_socket.close()
server_socket.close()
sys.exit()
Я протестировал его с Microsoft Edge, и он отлично работает с выводом ниже:
Starting up http-server, serving ./
Available on:
http://localhost:8080
Hit CTRL-BREAK to stop the server
Connected by: 127.0.0.1:60998
Filename to get: test.html
Но после того, как я переключил свой браузер на Chrome, произошло нечто очень странное.
Starting up http-server, serving ./
Available on:
http://localhost:8080
Hit CTRL-BREAK to stop the server
Connected by: 127.0.0.1:61332
Filename to get: test.html
Connected by: 127.0.0.1:61333
Filename to get: favicon.ico
Connected by: 127.0.0.1:61335
Traceback (most recent call last):
File "http-server.py", line 20, in <module>
filename = message.split()[1]
IndexError: list index out of range
Кажется, что Chrome открыл три соединения, но использовал только два из них.Последнее соединение не отправило ни одного сообщения на сервер.