nghttp3 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ module Nghttp3
2
+ class Error < StandardError
3
+ end
4
+
5
+ class InvalidArgumentError < Error
6
+ end
7
+
8
+ class InvalidStateError < Error
9
+ end
10
+
11
+ class WouldBlockError < Error
12
+ end
13
+
14
+ class StreamInUseError < Error
15
+ end
16
+
17
+ class MalformedHTTPHeaderError < Error
18
+ end
19
+
20
+ class MalformedHTTPMessagingError < Error
21
+ end
22
+
23
+ class QPACKFatalError < Error
24
+ end
25
+
26
+ class QPACKHeaderTooLargeError < Error
27
+ end
28
+
29
+ class StreamNotFoundError < Error
30
+ end
31
+
32
+ class ConnClosingError < Error
33
+ end
34
+
35
+ class StreamDataOverflowError < Error
36
+ end
37
+
38
+ class FatalError < Error
39
+ end
40
+
41
+ class NoMemError < Error
42
+ end
43
+
44
+ class CallbackFailureError < Error
45
+ end
46
+ end
@@ -0,0 +1,37 @@
1
+ module Nghttp3
2
+ class Headers
3
+ include Enumerable[Array[String]]
4
+
5
+ def initialize: (?Hash[String | Symbol, String] hash) -> void
6
+
7
+ def []: (String | Symbol name) -> String?
8
+ def []=: (String | Symbol name, String | _ToS value) -> String
9
+
10
+ def delete: (String | Symbol name) -> String?
11
+ def key?: (String | Symbol name) -> bool
12
+ alias has_key? key?
13
+ alias include? key?
14
+
15
+ def each: () { (String name, String value) -> void } -> void
16
+ | () -> Enumerator[Array[String], void]
17
+
18
+ def merge!: (Hash[String | Symbol, String] | Headers other) -> self
19
+ def merge: (Hash[String | Symbol, String] | Headers other) -> Headers
20
+
21
+ def to_h: () -> Hash[String, String]
22
+ alias to_hash to_h
23
+
24
+ def size: () -> Integer
25
+ alias length size
26
+
27
+ def empty?: () -> bool
28
+ def clear: () -> self
29
+ def dup: () -> Headers
30
+
31
+ def inspect: () -> String
32
+
33
+ private
34
+
35
+ def normalize_name: (String | Symbol name) -> String
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Nghttp3
2
+ class Info
3
+ def age: () -> Integer
4
+ def version_num: () -> Integer
5
+ def version_str: () -> String
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Nghttp3
2
+ class NV
3
+ def initialize: (String name, String value, ?flags: Integer) -> void
4
+
5
+ def name: () -> String
6
+ def value: () -> String
7
+ def flags: () -> Integer
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ module Nghttp3
2
+ module QPACK
3
+ class Encoder
4
+ # Creates a new QPACK encoder
5
+ def initialize: (Integer max_dtable_capacity) -> void
6
+
7
+ # Encodes headers for a given stream
8
+ def encode: (Integer stream_id, Array[NV] headers) -> { prefix: String, data: String, encoder_stream: String }
9
+
10
+ # Reads decoder stream data
11
+ def read_decoder: (String data) -> Integer
12
+
13
+ # Sets the maximum dynamic table capacity
14
+ def max_dtable_capacity=: (Integer capacity) -> Integer
15
+
16
+ # Sets the maximum number of blocked streams
17
+ def max_blocked_streams=: (Integer num) -> Integer
18
+
19
+ # Returns the number of currently blocked streams
20
+ def num_blocked_streams: () -> Integer
21
+ end
22
+
23
+ class Decoder
24
+ # Creates a new QPACK decoder
25
+ def initialize: (Integer max_dtable_capacity, Integer max_blocked_streams) -> void
26
+
27
+ # Decodes headers from a stream
28
+ def decode: (Integer stream_id, String data, ?fin: bool) -> { headers: Array[{ name: String, value: String, token: Integer }]?, blocked: bool, consumed: Integer }
29
+
30
+ # Reads encoder stream data
31
+ def read_encoder: (String data) -> Integer
32
+
33
+ # Returns data to be sent on the decoder stream
34
+ def decoder_stream_data: () -> String
35
+
36
+ # Cancels decoding for the given stream
37
+ def cancel_stream: (Integer stream_id) -> void
38
+
39
+ # Sets the maximum dynamic table capacity
40
+ def max_dtable_capacity=: (Integer capacity) -> Integer
41
+
42
+ # Returns the current insert count
43
+ def insert_count: () -> Integer
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ module Nghttp3
2
+ class Request
3
+ attr_reader method: String
4
+ attr_reader scheme: String
5
+ attr_reader authority: String?
6
+ attr_reader path: String
7
+ attr_reader headers: Headers
8
+ attr_reader body: String?
9
+
10
+ def initialize: (
11
+ method: String | Symbol,
12
+ path: String,
13
+ ?scheme: String,
14
+ ?authority: String?,
15
+ ?headers: Hash[String, String] | Headers,
16
+ ?body: String?
17
+ ) -> void
18
+
19
+ def to_nv_array: () -> Array[NV]
20
+ def body?: () -> bool
21
+ def inspect: () -> String
22
+
23
+ def self.get: (String url, ?headers: Hash[String, String]) -> Request
24
+ def self.post: (String url, ?body: String?, ?headers: Hash[String, String]) -> Request
25
+ def self.put: (String url, ?body: String?, ?headers: Hash[String, String]) -> Request
26
+ def self.delete: (String url, ?headers: Hash[String, String]) -> Request
27
+ def self.head: (String url, ?headers: Hash[String, String]) -> Request
28
+ def self.patch: (String url, ?body: String?, ?headers: Hash[String, String]) -> Request
29
+ def self.options: (String url, ?headers: Hash[String, String]) -> Request
30
+
31
+ private
32
+
33
+ def self.build_from_url: (String method, String url, ?body: String?, ?headers: Hash[String, String]) -> Request
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ module Nghttp3
2
+ class Response
3
+ attr_reader stream_id: Integer
4
+ attr_accessor status: Integer?
5
+ attr_reader headers: Headers
6
+ attr_accessor body: String?
7
+
8
+ def initialize: (
9
+ stream_id: Integer,
10
+ ?status: Integer?,
11
+ ?headers: Hash[String, String]? | Headers?,
12
+ ?body: String?
13
+ ) -> void
14
+
15
+ def to_nv_array: () -> Array[NV]
16
+
17
+ def write_headers: (?Hash[String, String] extra_headers) -> self
18
+ def headers_sent?: () -> bool
19
+
20
+ def write: (String | _ToS chunk) -> self
21
+ def body_chunks: () -> Array[String]
22
+ def body_from_chunks: () -> String
23
+
24
+ def finish: () -> self
25
+ def finished?: () -> bool
26
+
27
+ def body?: () -> bool
28
+ def effective_body: () -> String?
29
+
30
+ def append_body: (String data) -> self
31
+
32
+ def inspect: () -> String
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module Nghttp3
2
+ class Server
3
+ attr_reader connection: Connection
4
+ attr_reader settings: Settings
5
+ attr_reader requests: Hash[Integer, Request]
6
+ attr_reader responses: Hash[Integer, Response]
7
+
8
+ def initialize: (?settings: Settings?) -> void
9
+
10
+ def bind_streams: (control: Integer, qpack_encoder: Integer, qpack_decoder: Integer) -> self
11
+ def streams_bound?: () -> bool
12
+
13
+ def on_request: () { (Request request, Response response) -> void } -> self
14
+
15
+ def pump_writes: () { (Integer stream_id, String data, bool fin) -> Integer? } -> self
16
+ def read_stream: (Integer stream_id, String data, ?fin: bool) -> Integer
17
+ def add_ack_offset: (Integer stream_id, Integer n) -> self
18
+
19
+ def close: () -> nil
20
+ def closed?: () -> bool
21
+
22
+ private
23
+
24
+ def setup_callbacks: () -> Callbacks
25
+ def on_begin_headers: (Integer stream_id) -> void
26
+ def on_recv_header: (Integer stream_id, String name, String value, Integer flags) -> void
27
+ def on_end_headers: (Integer stream_id, bool fin) -> void
28
+ def on_recv_data: (Integer stream_id, String data) -> void
29
+ def on_end_stream: (Integer stream_id) -> void
30
+ def on_stream_close: (Integer stream_id, Integer app_error_code) -> void
31
+ def process_request: (Integer stream_id) -> void
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module Nghttp3
2
+ class Settings
3
+ def self.default: () -> Settings
4
+
5
+ def initialize: () -> void
6
+
7
+ def max_field_section_size: () -> Integer
8
+ def max_field_section_size=: (Integer value) -> Integer
9
+
10
+ def qpack_max_dtable_capacity: () -> Integer
11
+ def qpack_max_dtable_capacity=: (Integer value) -> Integer
12
+
13
+ def qpack_encoder_max_dtable_capacity: () -> Integer
14
+ def qpack_encoder_max_dtable_capacity=: (Integer value) -> Integer
15
+
16
+ def qpack_blocked_streams: () -> Integer
17
+ def qpack_blocked_streams=: (Integer value) -> Integer
18
+
19
+ def enable_connect_protocol: () -> bool
20
+ def enable_connect_protocol=: (boolish value) -> boolish
21
+
22
+ def h3_datagram: () -> bool
23
+ def h3_datagram=: (boolish value) -> boolish
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ module Nghttp3
2
+ class StreamManager
3
+ BIDI_CLIENT: Integer
4
+ BIDI_SERVER: Integer
5
+ UNI_CLIENT: Integer
6
+ UNI_SERVER: Integer
7
+
8
+ def initialize: (is_server: bool) -> void
9
+
10
+ def allocate_bidi_stream_id: () -> Integer
11
+ def allocate_uni_stream_id: () -> Integer
12
+
13
+ def register_stream: (Integer stream_id, ?type: :bidi | :uni) -> void
14
+ def close_stream: (Integer stream_id) -> void
15
+ def remove_stream: (Integer stream_id) -> void
16
+
17
+ def stream_active?: (Integer stream_id) -> bool
18
+ def active_stream_ids: () -> Array[Integer]
19
+ def stream_info: (Integer stream_id) -> Hash[Symbol, Symbol]?
20
+
21
+ def client_initiated?: (Integer stream_id) -> bool
22
+ def server_initiated?: (Integer stream_id) -> bool
23
+ def bidirectional?: (Integer stream_id) -> bool
24
+ def unidirectional?: (Integer stream_id) -> bool
25
+ end
26
+ end
data/sig/nghttp3.rbs ADDED
@@ -0,0 +1,64 @@
1
+ module Nghttp3
2
+ VERSION: String
3
+
4
+ # nghttp3 library compile-time constants
5
+ NGHTTP3_VERSION: String
6
+ NGHTTP3_VERSION_NUM: Integer
7
+ NGHTTP3_VERSION_AGE: Integer
8
+
9
+ # nghttp3 error code constants
10
+ NGHTTP3_ERR_INVALID_ARGUMENT: Integer
11
+ NGHTTP3_ERR_INVALID_STATE: Integer
12
+ NGHTTP3_ERR_WOULDBLOCK: Integer
13
+ NGHTTP3_ERR_STREAM_IN_USE: Integer
14
+ NGHTTP3_ERR_MALFORMED_HTTP_HEADER: Integer
15
+ NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING: Integer
16
+ NGHTTP3_ERR_QPACK_FATAL: Integer
17
+ NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE: Integer
18
+ NGHTTP3_ERR_STREAM_NOT_FOUND: Integer
19
+ NGHTTP3_ERR_CONN_CLOSING: Integer
20
+ NGHTTP3_ERR_STREAM_DATA_OVERFLOW: Integer
21
+ NGHTTP3_ERR_FATAL: Integer
22
+ NGHTTP3_ERR_NOMEM: Integer
23
+ NGHTTP3_ERR_CALLBACK_FAILURE: Integer
24
+
25
+ # NV flag constants
26
+ NV_FLAG_NONE: Integer
27
+ NV_FLAG_NEVER_INDEX: Integer
28
+ NV_FLAG_NO_COPY_NAME: Integer
29
+ NV_FLAG_NO_COPY_VALUE: Integer
30
+ NV_FLAG_TRY_INDEX: Integer
31
+
32
+ # Data flag constants
33
+ DATA_FLAG_NONE: Integer
34
+ DATA_FLAG_EOF: Integer
35
+ DATA_FLAG_NO_END_STREAM: Integer
36
+
37
+ # HTTP/3 application error code constants
38
+ H3_NO_ERROR: Integer
39
+ H3_GENERAL_PROTOCOL_ERROR: Integer
40
+ H3_INTERNAL_ERROR: Integer
41
+ H3_STREAM_CREATION_ERROR: Integer
42
+ H3_CLOSED_CRITICAL_STREAM: Integer
43
+ H3_FRAME_UNEXPECTED: Integer
44
+ H3_FRAME_ERROR: Integer
45
+ H3_EXCESSIVE_LOAD: Integer
46
+ H3_ID_ERROR: Integer
47
+ H3_SETTINGS_ERROR: Integer
48
+ H3_MISSING_SETTINGS: Integer
49
+ H3_REQUEST_REJECTED: Integer
50
+ H3_REQUEST_CANCELLED: Integer
51
+ H3_REQUEST_INCOMPLETE: Integer
52
+ H3_MESSAGE_ERROR: Integer
53
+ H3_CONNECT_ERROR: Integer
54
+ H3_VERSION_FALLBACK: Integer
55
+
56
+ # Returns runtime version info, or nil if least_version requirement not met
57
+ def self.library_version: (?Integer least_version) -> Info?
58
+
59
+ # Returns true if the given error code represents a fatal error
60
+ def self.err_is_fatal?: (Integer error_code) -> bool
61
+
62
+ # Returns a textual representation of the given error code
63
+ def self.strerror: (Integer error_code) -> String
64
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nghttp3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Nakamura
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: "[WIP] Ruby bindings for nghttp3, a C library implementing HTTP/3 mapping
13
+ over QUIC and QPACK encoder/decoder."
14
+ email:
15
+ - yusuke1994525@gmail.com
16
+ executables: []
17
+ extensions:
18
+ - ext/nghttp3/extconf.rb
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".clang-format"
22
+ - ".vscode/extensions.json"
23
+ - ".vscode/settings.json"
24
+ - CHANGELOG.md
25
+ - CODE_OF_CONDUCT.md
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - ext/nghttp3/extconf.rb
30
+ - ext/nghttp3/nghttp3.c
31
+ - ext/nghttp3/nghttp3.h
32
+ - ext/nghttp3/nghttp3_callbacks.c
33
+ - ext/nghttp3/nghttp3_connection.c
34
+ - ext/nghttp3/nghttp3_nv.c
35
+ - ext/nghttp3/nghttp3_qpack.c
36
+ - ext/nghttp3/nghttp3_settings.c
37
+ - lib/nghttp3.rb
38
+ - lib/nghttp3/client.rb
39
+ - lib/nghttp3/headers.rb
40
+ - lib/nghttp3/request.rb
41
+ - lib/nghttp3/response.rb
42
+ - lib/nghttp3/server.rb
43
+ - lib/nghttp3/stream_manager.rb
44
+ - lib/nghttp3/version.rb
45
+ - sig/nghttp3.rbs
46
+ - sig/nghttp3/callbacks.rbs
47
+ - sig/nghttp3/client.rbs
48
+ - sig/nghttp3/connection.rbs
49
+ - sig/nghttp3/error.rbs
50
+ - sig/nghttp3/headers.rbs
51
+ - sig/nghttp3/info.rbs
52
+ - sig/nghttp3/nv.rbs
53
+ - sig/nghttp3/qpack.rbs
54
+ - sig/nghttp3/request.rbs
55
+ - sig/nghttp3/response.rbs
56
+ - sig/nghttp3/server.rbs
57
+ - sig/nghttp3/settings.rbs
58
+ - sig/nghttp3/stream_manager.rbs
59
+ homepage: https://github.com/unasuke/nghttp3
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ homepage_uri: https://github.com/unasuke/nghttp3
64
+ source_code_uri: https://github.com/unasuke/nghttp3
65
+ changelog_uri: https://github.com/unasuke/nghttp3/blob/main/CHANGELOG.md
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 3.2.0
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 4.0.3
81
+ specification_version: 4
82
+ summary: "[WIP] Ruby bindings for nghttp3, an HTTP/3 library"
83
+ test_files: []