Giter Club home page Giter Club logo

Comments (5)

kofalt avatar kofalt commented on August 26, 2024

Oops: I didn't think far enough ahead to try my example with a browser; it looks like the newline issue is curl's fault, not gocraft/web's. In Firefox, the above example works unmodified.

If you could answer the second question Re: long-running requests we can close this out :)

from web.

cypriss avatar cypriss commented on August 26, 2024

@kofalt to be honest I think this could be used to implement an SSE-type of thing, but I've never done it. There's also packages like this for SSE: https://github.com/antage/eventsource. It would be pretty easy to use that with gocraft/web with a small wrapper.

from web.

kofalt avatar kofalt commented on August 26, 2024

Hmm, fair enough. I did notice that when I modified my example thus:

func (c *Context) SayHello(rw web.ResponseWriter, req *web.Request) {
    Println("Running handler")

    for n := 1; n < 10; n++ {
        Fprint(rw, strings.Repeat("Hello ", c.HelloCount), "World!\n")
        rw.Flush()
        time.Sleep(1 * time.Second)
    }
    Fprint(rw, strings.Repeat("Hello ", c.HelloCount), "World!\n")
}

And made multiple requests at the same time, each would block until the previous request had finished. The Running handler messages only printed one at a time also.

This gives the appearance of gocraft/web only handling one request at a time; thoughts?

from web.

cypriss avatar cypriss commented on August 26, 2024

@kofalt I think Firefox only sends 1 request at a time. Try using firefox + chrome.

from web.

kofalt avatar kofalt commented on August 26, 2024

You're absolutely right. How embarassing. This appears to be unaffected by Firefox's network.http.max-connections-per-server setting (possibly because it's the same URL).

Notably, Chrome won't print any output until the mesage is done, so instead by using Firefox & curl, or multiple runs of curl, the correct behavior can be observed.

Thanks for your help getting started :)

from web.

Related Issues (20)

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.