llhttp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c367e8870364d3400220233c434081a75a6467ff864f50d1a24a83ee0abf90dd
4
+ data.tar.gz: 74628e99e4c978fcbaa6a37ba2b9bb3473cacaab0fd69ca1196384aa8781024a
5
+ SHA512:
6
+ metadata.gz: c2e2249e81dee3cc6036debf2144f0ca64597a17dd66de4ceaa4b889860070bc09476bfa1a0f5a82b05bb9941d5719f8adcf28f01a2d665314e41860f49bed68
7
+ data.tar.gz: 06dccd9bb5b78bc7f62d06293d98fab34b325382ed0873b4702d9ef3fd04a73075e102358655c72474a0a1dc92eee20791e29895ce8c6c8a63b2bb9926cf5693
File without changes
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ This software is licensed under the MIT License.
2
+
3
+ Copyright Bryan Powell, 2020.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to permit
10
+ persons to whom the Software is furnished to do so, subject to the
11
+ following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # llhttp
2
+
3
+ Ruby bindings for [llhttp](https://github.com/nodejs/llhttp).
4
+
5
+ ## Install
6
+
7
+ ```
8
+ gem install llhttp
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ require "llhttp"
15
+
16
+ # Define a delegate class for handling callbacks:
17
+ #
18
+ class Delegate < LLHttp::Delegate
19
+ def on_message_begin
20
+ ...
21
+ end
22
+ end
23
+
24
+ delegate = Delegate.new
25
+
26
+ # Create a parser:
27
+ #
28
+ parser = LLHttp::Parser.new(delegate)
29
+
30
+ # Parse a request:
31
+ #
32
+ parser << "GET / HTTP/1.1\r\n\r\n"
33
+
34
+ # Reset the parser for the next request:
35
+ #
36
+ parser.finish
37
+ ```
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ dir_config "llhttp_ext"
6
+
7
+ create_makefile "llhttp_ext"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LLHttp
4
+ require_relative "llhttp/delegate"
5
+ require_relative "llhttp/error"
6
+ require_relative "llhttp/parser"
7
+ require_relative "llhttp/version"
8
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LLHttp
4
+ # Delegate for handling callbacks. Subclass this, implementing the necessary methods.
5
+ #
6
+ class Delegate
7
+ def on_message_begin
8
+ end
9
+
10
+ def on_url(url)
11
+ end
12
+
13
+ def on_status(status)
14
+ end
15
+
16
+ def on_header_field(field)
17
+ end
18
+
19
+ def on_header_value(value)
20
+ end
21
+
22
+ def on_headers_complete
23
+ end
24
+
25
+ def on_body(body)
26
+ end
27
+
28
+ def on_message_complete
29
+ end
30
+
31
+ def on_chunk_header
32
+ end
33
+
34
+ def on_chunk_complete
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LLHttp
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LLHttp
4
+ # Wraps an llhttp context for parsing http requests and responses.
5
+ #
6
+ # = Finishing
7
+ #
8
+ # Call `LLHttp::Parser#finish` when processing is complete for the current request or response.
9
+ #
10
+ # = Introspection
11
+ #
12
+ # `LLHttp::Parser#keep_alive?` returns `true` if there might be any other messages following the last that was successfuly parsed.
13
+ #
14
+ class Parser
15
+ LLHTTP_TYPES = {both: 0, request: 1, response: 2}.freeze
16
+
17
+ attr_reader :type
18
+
19
+ def initialize(delegate, type: :both)
20
+ @type, @delegate = type.to_sym, delegate
21
+
22
+ llhttp_init(LLHTTP_TYPES.fetch(@type))
23
+ end
24
+ end
25
+ end
26
+
27
+ require_relative "llhttp_ext"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LLHttp
4
+ VERSION = "0.0.1"
5
+
6
+ def self.version
7
+ VERSION
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: llhttp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Powell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby bindings for llhttp.
14
+ email: bryan@bryanp.org
15
+ executables: []
16
+ extensions:
17
+ - ext/llhttp/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - LICENSE
22
+ - README.md
23
+ - ext/llhttp/extconf.rb
24
+ - lib/llhttp.rb
25
+ - lib/llhttp/delegate.rb
26
+ - lib/llhttp/error.rb
27
+ - lib/llhttp/llhttp_ext.bundle
28
+ - lib/llhttp/parser.rb
29
+ - lib/llhttp/version.rb
30
+ homepage: https://metabahn.com/code/llhttp
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.5.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.1.2
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Ruby bindings for llhttp.
53
+ test_files: []