Giter Site home page Giter Site logo

Comments (1)

dnwade avatar dnwade commented on September 17, 2024

I can confirm this error. Here are three examples using your subclass:

l = Coolio::Loop.default
msn = MyHttp.connect("www.msn.com").attach(l)
msn.request("GET", '/')
l.run

This prints "HTTP FINISHED". The response_header contains a "content-length" header (and no "transfer-encoding: chunked" header).

l = Coolio::Loop.default
ip = MyHttp.connect("jsonip.com).attach(l)
ip.request("GET", '/')
l.run

This too prints "HTTP FINISHED". There is a "transfer-encoding: chunked" header present (but no "content-length" header).

Finally, trying your "www.google.com" example does not print "HTTP FINISHED", i.e.: on_request_complete is not called. And both those headers are not defined.

I think this problem can be traced to the following source from Coolio::HttpClient#process_body (cool.io/http_client.rb):

  if @bytes_remaining.nil?
    on_body_data @data.read
    return false
  end

This code is evaluated if and only if the server has not set both the "Transfer-Encoding: chunked" header and the "Content-Length" header since Coolio::HttpClient sets @bytes_remaining to nil. Hence, @State is never changed from :body to :finished and on_request_complete never gets called.

One work around would be to set a callback that calls on_request_complete whenever the server closes the TCP connection and those two HTTP headers are unset. I'm not entirely sure about the correct way to do this with the Coolio API though.

Would you define HttpClient#on_close? If so, how?

from cool.io.

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.