title: Safari Server Sent Event (SSE) Infinte Loop
body: <p>I am having issues with server-send events (SSE) in Safari 9 and Safari 10. The SSE connection opens, immediately closes and then reconnects in an infinite loop.</p>
  
  <p>This is the client side code:</p>
  
  <pre><code>var events = new EventSource("/stream/events")
  </code></pre>
  
  <p>These are the http response headers:</p>
  
  <pre><code>&gt; GET /stream/events HTTP/1.1
  &gt; User-Agent: curl/7.43.0
  &gt; Accept: */*
  &gt; 
  &lt; HTTP/1.1 200 OK
  &lt; Access-Control-Allow-Origin: *
  &lt; Cache-Control: no-cache
  &lt; Connection: keep-alive
  &lt; Content-Type: text/event-stream
  &lt; Expires: Thu, 01 Jan 1970 00:00:00 GMT
  &lt; Last-Modified: Tue, 19 Sep 2017 05:28:22 GMT
  &lt; Strict-Transport-Security: max-age=31536000
  &lt; X-Accel-Buffering: no
  &lt; X-Content-Type-Options: nosniff
  &lt; X-Frame-Options: DENY
  &lt; X-Xss-Protection: 1; mode=block
  &lt; Date: Tue, 19 Sep 2017 05:28:22 GMT
  &lt; Transfer-Encoding: chunked
  </code></pre>
  
  <p>Some additional notes:</p>
  
  <ul>
  <li>I tested in Chrome and Firefox and cannot repeat</li>
  <li>I tested in Safari <strong>without https</strong> and cannot repeat</li>
  <li>I tested in Safari <strong>with https</strong> and can repeat</li>
  <li>The https certificates are auto-generated using Lets Encrypt</li>
  <li>The backend server is written in Go and uses http/2 by default</li>
  </ul>
  
  <p>The fact that I can only repeat in Safari with https is interesting. I am therefore wondering if there are any known issues with SSE and https, or if there is anything else I might be misconfiguring or missing here.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have isolated the problem and found a correlation to the protocol. When the http2 protocol is enabled, I am able to reproduce this issue. When http2 is disabled on the server, I am no longer able to reproduce this problem.</p>
  
  <p>I used the following server patch to verify:</p>
  
  <pre><code>--- before.go   2017-09-19 13:31:45.668891000 -0400
  +++ after.go    2017-09-19 13:31:55.100891000 -0400
  @@ -2,6 +2,6 @@
              Addr: ":443",
              TLSConfig: &amp;tls.Config{
                  GetCertificate: manager.GetCertificate,
  -               NextProtos:     []string{"h2", "http/1.1"},
  +               NextProtos:     []string{"http/1.1"},
              },
          }
  </code></pre>