Git Product home page Git Product logo

Comments (4)

donovanhide avatar donovanhide commented on August 23, 2024

Hi, first of all thanks for trying out the code and the bug report :-)

To answer your last question first, I haven't used this package with any other middleware systems. It looks like the Flush() here is causing your problem:

https://github.com/donovanhide/eventsource/blob/master/server.go#L78

which invokes:

https://github.com/golang/go/blob/2c12b81739ec2cb85073e125748fcbf5d2febb2c/src/net/http/server.go#L279

which writes the header :-) This is needed for eventsource streams which don't start broadcasting immediately (unlike your example code) so that the client can inspect the headers first and know that the response is in fact an event stream and the carry on waiting for some events to come later.

So, to solve your actual problem, you could avoid n.Run(...) and set up your own http.ListenAndServe() which has a router that sends some request paths to your SSE server and others to a Negroni set of handlers. I guess the question is whether you actually need some middleware functionality for your eventsource handler? If so, I guess this test needs beefing up as there may be some issue within negroni itself when handling flushes:

https://github.com/codegangsta/negroni/blob/c7477ad8e330bef55bf1ebe300cf8aa67c492d1b/response_writer_test.go#L144-L150

Let me know if you need more help!

from eventsource.

donovanhide avatar donovanhide commented on August 23, 2024

This looks like the easiest way to solve what you are doing:
https://github.com/codegangsta/negroni#route-specific-middleware

from eventsource.

jeromenerf avatar jeromenerf commented on August 23, 2024

Thanks @donovanhide !

I took some time to try and reproduce the bug but went short on going further.

Anyway, yes, the eventsource stream could benefit from the existing middlewares such as permissions, logger and so on.

I'll keep you in touch ;)

from eventsource.

donovanhide avatar donovanhide commented on August 23, 2024

Actually, there was a simple fix :-) See if it works for you now!

from eventsource.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.