Skip to content

Instantly share code, notes, and snippets.

@tmm1
Forked from jordansissel/http_parser.diff
Created March 4, 2012 08:38
Show Gist options
  • Save tmm1/1971394 to your computer and use it in GitHub Desktop.
Save tmm1/1971394 to your computer and use it in GitHub Desktop.
diff --git a/ext/ruby_http_parser/ruby_http_parser.c b/ext/ruby_http_parser/ruby_http_parser.c
index 119d7e1..5650652 100644
--- a/ext/ruby_http_parser/ruby_http_parser.c
+++ b/ext/ruby_http_parser/ruby_http_parser.c
@@ -320,6 +320,9 @@ VALUE Parser_execute(VALUE self, VALUE data) {
size_t nparsed = ryah_http_parser_execute(&wrapper->parser, &settings, ptr, len);
if (wrapper->parser.upgrade) {
+ if (RTEST(wrapper->stopped))
+ nparsed += 1;
+
rb_str_cat(wrapper->upgrade_data, ptr + nparsed, len - nparsed);
} else if (nparsed != (size_t)len) {
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
index 80369dd..d863060 100644
--- a/spec/parser_spec.rb
+++ b/spec/parser_spec.rb
@@ -281,6 +281,8 @@ describe HTTP::Parser do
@parser.on_headers_complete = proc { |e| :stop }
offset = (@parser << request)
+ @parser.upgrade?.should be_true
+ @parser.upgrade_data.should == ''
offset.should == request.length
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment