python - Use HTTP/1.1 with SimpleHTTPRequestHandler -


when use http/1.1 simplehttprequesthandler, loading page pulls in other resources hang after second resource.

here small reproducer:

from simplehttpserver import simplehttprequesthandler basehttpserver import httpserver  class myrequesthandler(simplehttprequesthandler):     #protocol_version = "http/1.0"   # works     protocol_version = "http/1.1"   # hangs  server = httpserver(("localhost", 7080), myrequesthandler) server.serve_forever() 

with above server, following html hang when browser tries load b.png:

<html>     <body>         <img src="a.png">         <img src="b.png">     </body> </html> 

can http/1.1 used simplehttpserver module , if so, how? note adding forkingmixin or threadingmixin server allow things progress, however, seems should possible without either of mixins.

the behavior see due 3 reasons:

  • basehttpserver.httpserver default capable of handling 1 request @ time
  • most user agents (browsers) open more 1 connection given host @ time
  • most user agents use keep-alive feature of http 1.1 , not close connection after received requested entities

what see browser able entities requested using first connection opens server. page , possibly of resources. @ same time browser opens additional connections rest of resources these connections can't proceed because server tied first one. reason server tied first 1 although browser had received entities requested using connection not close in case reused more entities in near future (the server not close connection on side either browser specified version 1.1 of http , sent connection: keep-alive header). after first connection times out, server starts handling next waiting connection additional resource(s) being downloaded (all requested using specific connection). if wait long enough browser manages resources. can observe difference when set network.http.max-persistent-connections-per-server preference 1 (instead default 6) in firefox or analogous in other browsers. then, resources requested using same connection, retrieval of each starts previous retrieved without delay.

i'd thank marienz #python irc channel on freenode.net problem.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -