-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from metabahn/add/reset
Add support for resetting the parser
- Loading branch information
Showing
10 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,5 +33,5 @@ parser << "GET / HTTP/1.1\r\n\r\n" | |
|
||
# Reset the parser for the next request: | ||
# | ||
parser.finish | ||
parser.reset | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,5 +33,5 @@ parser << "GET / HTTP/1.1\r\n\r\n" | |
|
||
# Reset the parser for the next request: | ||
# | ||
parser.finish | ||
parser.reset | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ def run | |
ensure | ||
stream.close | ||
|
||
@parser.finish | ||
@parser.reset | ||
end | ||
|
||
private def parse_next(stream) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "support/context/parsing" | ||
|
||
RSpec.describe "parsing responses without a content length" do | ||
include_context "parsing" | ||
|
||
shared_examples "examples" do | ||
let(:extension) { | ||
proc { | ||
def on_message_begin | ||
@calls << :on_message_begin | ||
end | ||
|
||
def on_header_field(_) | ||
@calls << :on_header_field | ||
end | ||
|
||
def on_header_value(_) | ||
@calls << :on_header_value | ||
end | ||
|
||
def on_headers_complete | ||
@calls << :on_headers_complete | ||
end | ||
|
||
def on_body(_) | ||
@calls << :on_body | ||
end | ||
|
||
def on_message_complete | ||
@calls << :on_message_complete | ||
end | ||
} | ||
} | ||
|
||
it "parses correctly" do | ||
10_000.times do | ||
parse | ||
|
||
instance.reset | ||
end | ||
|
||
expect(delegate.calls.count(:on_message_begin)).to eq(10_000) | ||
expect(delegate.calls.count(:on_header_field)).to eq(0) | ||
expect(delegate.calls.count(:on_header_value)).to eq(0) | ||
expect(delegate.calls.count(:on_headers_complete)).to eq(10_000) | ||
expect(delegate.calls.count(:on_body)).to eq(0) | ||
expect(delegate.calls.count(:on_message_complete)).to eq(0) | ||
end | ||
end | ||
|
||
context "response" do | ||
let(:type) { | ||
:response | ||
} | ||
|
||
let(:fixture) { | ||
:response_sans_content_length | ||
} | ||
|
||
include_examples "examples" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters