lepture / python-livereload

livereload server in python
https://livereload.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
1.02k stars 150 forks source link

Fix LiveScriptInjector so that <script> is never injected twice #259

Closed Lucas-C closed 2 years ago

Lucas-C commented 2 years ago

With a web page containing two <head> sections, the current version of livereload breaks with this error:

[E 220721 20:20:24 web:1791] Uncaught exception GET / (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:5500', method='GET', uri='/', version='HTTP/1.1', remote_ip='127.0.0.1'
)
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/tornado/web.py", line 1706, in _execute
        result = await result
      File "/usr/local/lib/python3.8/site-packages/tornado/web.py", line 2650, in get
        await self.flush()
      File "/usr/local/lib/python3.8/site-packages/tornado/web.py", line 1095, in flush
        return self.request.connection.write_headers(
      File "/usr/local/lib/python3.8/site-packages/tornado/http1connection.py", line 465, in write_headers
        data += self._format_chunk(chunk)
      File "/usr/local/lib/python3.8/site-packages/tornado/http1connection.py", line 477, in _format_chunk
        raise httputil.HTTPOutputError(
    tornado.httputil.HTTPOutputError: Tried to write more data than Content-Length

This PR makes sure such situation never happens