-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error reading from socket: Could not parse data #589
Comments
I confirm this can be reproduced on Related issues and commits |
Here is example reduced to require 'http'
parser = HTTP::Response::Parser.new
parser.add("HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: application/json\r\nMyHeader")
parser.add(": val\r\n\r\n{}") it raises And here is example reduced to # script.rb
require 'http-parser'
class MyParser
attr_reader :headers
def initialize
@state = HttpParser::Parser.new_instance { |i| i.type = :response }
@parser = HttpParser::Parser.new(self)
end
def add(data)
return self unless @parser.parse(@state, data)
raise IOError, "Could not parse data"
end
alias << add
def on_header_field(_response, field)
puts "[DEBUG] on_header_field: #{field.inspect}"
end
def on_header_value(_response, value)
puts "[DEBUG] on_header_value: #{value.inspect}"
end
def on_headers_complete(_response)
puts "[DEBUG] on_headers_complete"
end
def on_body(_response, chunk)
puts "[DEBUG] on_body: #{chunk.inspect}"
end
def on_message_complete(_response)
puts "[DEBUG] on_message_complete"
end
end
parser = MyParser.new
parser.add("HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: application/json\r\nMyHeader")
puts "-------"
parser.add(": val\r\n\r\n{}")
# → ruby script.rb
# [DEBUG] on_header_field: "Content-Length"
# [DEBUG] on_header_value: "2"
# [DEBUG] on_header_field: "Content-Type"
# [DEBUG] on_header_value: "application/json"
# [DEBUG] on_header_field: "MyHeader"
# -------
# [DEBUG] on_header_field: ""
# [DEBUG] on_header_value: "val"
# [DEBUG] on_headers_complete
# [DEBUG] on_body: "{}"
# [DEBUG] on_message_complete The problem is obvious now:
This means that
and because of this parser fails. |
I think I was wrong. Apparently this is just how parser = MyParser.new
body = "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\n{}"
body.each_char { |char| parser.add(char) }
# [DEBUG] on_header_field: "C"
# [DEBUG] on_header_field: "o"
# [DEBUG] on_header_field: "n"
# [DEBUG] on_header_field: "t"
# [DEBUG] on_header_field: "e"
# [DEBUG] on_header_field: "n"
# [DEBUG] on_header_field: "t"
# [DEBUG] on_header_field: "-"
# [DEBUG] on_header_field: "L"
# [DEBUG] on_header_field: "e"
# [DEBUG] on_header_field: "n"
# [DEBUG] on_header_field: "g"
# [DEBUG] on_header_field: "t"
# [DEBUG] on_header_field: "h"
# [DEBUG] on_header_field: ""
# [DEBUG] on_header_value: "2"
# [DEBUG] on_header_value: ""
# [DEBUG] on_headers_complete
# [DEBUG] on_body: "{"
# [DEBUG] on_body: "}"
# [DEBUG] on_message_complete So |
Thank you once again! |
Hi,
I'm investigating an error that is raised when making http request to one of the remote APIs. I don't want to post that request as there are some secrets used, but I think I was able to create minimal reproducible example:
Here is the error that is returned:
Error is not returned when using
http
version <=4.1.1
The text was updated successfully, but these errors were encountered: