The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
.as()
it isn't working expected a function type, not (Proc(String) | Proc(String, String) | Nil)
| Nil
, since i'm also using overloading for a method that accepts (pattern : String, replace : String)
and (pattern : String, &block : Proc(String,String) | Proc(String))
Free Variables
take precedence over No Type Restriction
class HTTP::Client::Response
def self.from_io?(io, ignore_body = false, decompress = true, &block)
line = io.gets(4096, chomp: true)
return yield nil unless line
pieces = line.split(3)
if pieces.size < 2
# return yield new status_code: 200, body_io: ChunkedContent.new(io)
pieces = "HTTP/1.1 200 OK".split(3)
end
http_version = pieces[0]
raise "Unsupported HTTP version: #{http_version}" unless HTTP::SUPPORTED_VERSIONS.includes?(http_version)
status_code = pieces[1].to_i?
unless status_code && 100 <= status_code < 1000
raise "Invalid HTTP status code: #{pieces[1]}"
end
status = HTTP::Status.new(status_code)
status_message = pieces[2]? ? pieces[2].chomp : ""
body_type = HTTP::BodyType::OnDemand
body_type = HTTP::BodyType::Mandatory if mandatory_body?(status)
body_type = HTTP::BodyType::Prohibited if ignore_body
HTTP.parse_headers_and_body(io, body_type: body_type, decompress: decompress) do |headers, body|
return yield new status, nil, headers, status_message, http_version, body
end
nil
end
end
if pieces.size < 2
# return yield new status_code: 200, body_io: ChunkedContent.new(io)
pieces = "HTTP/1.1 200 OK".split(3)
end