raw_net_capture 1.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1d6cf8bbc933a2477cb83cbcb3d6dcbfdd24a31d
4
- data.tar.gz: 2f5ed8a2ffa6af154039ea1d2ec27ee6ec255a58
2
+ SHA256:
3
+ metadata.gz: 5bbb3ccfe245bd93d89e6ddbcca677d9f3117d3e4438f4e0a0848b6d88a938d2
4
+ data.tar.gz: fd845b1ee17db4a389c00986209b9f8cb31cdec1ccca5df2669f1fbf6939bb0e
5
5
  SHA512:
6
- metadata.gz: aea4d1138a7f2cdd04a8675f6975011218069e74fd5fa35078389c158a7b1dafffd5c2e18a80dc857a4d221fe6065381dd892e032ecf6eb9e7c51ff1634f8f52
7
- data.tar.gz: e5948bcdf2da1be5915bd72ac32458ab2ecf5e95cba15fbd07e41a9b5add9cc3dbe7189d6200f987deffb6aa430b709f9a031268c57064b25afc3b7099c4cc80
6
+ metadata.gz: 3fcb6307695e48b90530b5fdff48b8715c360cd9b85e95fb9ebc6d33138189a61450c1c1dec6932729cf5bd435d492bf255d671cfc607fe242f46e2b2cf720c2
7
+ data.tar.gz: 7e876740adee3f08c227054aec99f183f3c838b65adbe40b72884f0093ca8cc74f8f799b4a8bfdca48645510d7bbc5a90bd4939ce3ed9ddf736f2b2e73cd6909
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ module Net
4
+ class BufferedIO
5
+ private
6
+ alias_method :orig_rbuf_consume, :rbuf_consume
7
+ alias_method :orig_write0, :write0
8
+
9
+ def rbuf_consume(len = nil)
10
+ return orig_rbuf_consume(len) unless @debug_output
11
+
12
+ begin
13
+ saved_debug_output = @debug_output
14
+ @debug_output = nil
15
+ str = orig_rbuf_consume(len)
16
+ ensure
17
+ @debug_output = saved_debug_output
18
+ end
19
+
20
+ @debug_output << %Q[-> #{str.dump}\n]
21
+ @debug_output.received(str) if @debug_output.respond_to?(:received)
22
+ str
23
+ end
24
+
25
+ def write0(*strs)
26
+ return orig_write0(*strs) unless @debug_output
27
+
28
+ begin
29
+ saved_debug_output = @debug_output
30
+ @debug_output = nil
31
+ ret = orig_write0(*strs)
32
+ ensure
33
+ @debug_output = saved_debug_output
34
+ end
35
+
36
+ strs.each do |str|
37
+ @debug_output << str.dump
38
+ @debug_output.sent(str) if @debug_output.respond_to?(:sent)
39
+ end
40
+
41
+ ret
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ class RawHTTPCapture < StringIO
4
+ def initialize
5
+ super
6
+ reset
7
+ end
8
+
9
+ def received(data)
10
+ transactions.last.response.raw_io << data
11
+ end
12
+
13
+ def sent(data)
14
+ # when there are multiple requests on the same connection, E.g. redirection, we want the last one.
15
+ if transactions.last.response.raw_io.length > 0
16
+ reset
17
+ end
18
+
19
+ transactions.last.request.raw_io << data
20
+ end
21
+
22
+ def transactions
23
+ @transactions ||= []
24
+ end
25
+
26
+ private
27
+
28
+ def reset
29
+ transactions << Transaction.new
30
+ end
31
+
32
+ class Transaction
33
+ attr_reader :response, :request
34
+
35
+ def initialize
36
+ @request = Request.new
37
+ @response = Response.new
38
+ end
39
+
40
+ class Part
41
+ def body
42
+ @body ||= partitions[2]
43
+ end
44
+
45
+ def headers
46
+ @headers ||= partitions[0]
47
+ end
48
+
49
+ def raw_io
50
+ @raw_io ||= StringIO.new
51
+ end
52
+
53
+ def raw
54
+ @raw ||= raw_io.string
55
+ end
56
+
57
+ private
58
+
59
+ # headers and body
60
+ def partitions
61
+ @partitions ||= raw.partition("\r\n\r\n").map do |part|
62
+ part.empty? ? nil : part
63
+ end
64
+ end
65
+ end
66
+
67
+ class Response < Part; end
68
+ class Request < Part; end
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ class RawNetCapture < StringIO
4
+ attr_reader :raw_traffic
5
+
6
+ def initialize
7
+ super
8
+ reset
9
+ end
10
+
11
+ def received(data)
12
+ @raw_traffic << [:received, data]
13
+ end
14
+
15
+ def sent(data)
16
+ @raw_traffic << [:sent, data]
17
+ end
18
+
19
+ private
20
+
21
+ def reset
22
+ @raw_traffic = []
23
+ end
24
+ end
@@ -1,79 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- class RawNetCapture < StringIO
4
- attr_reader :raw_traffic
3
+ gem 'net-protocol'
5
4
 
6
- def initialize
7
- super
8
- reset
9
- end
10
-
11
- def received(data)
12
- @raw_traffic << [:received, data]
13
- end
14
-
15
- def sent(data)
16
- @raw_traffic << [:sent, data]
17
- end
18
-
19
- def reset
20
- @raw_traffic = []
21
- end
22
- end
23
-
24
- class RawHTTPCapture < StringIO
25
- attr_reader :raw_received, :raw_sent
26
-
27
- def initialize
28
- super
29
- reset
30
- end
31
-
32
- def reset
33
- @raw_received = StringIO.new
34
- @raw_sent = StringIO.new
35
- end
36
-
37
- def received(data)
38
- @raw_received << data
39
- end
40
-
41
- def sent(data)
42
- @raw_sent << data
43
- end
44
-
45
- def headers
46
- separator = "\r\n\r\n"
47
- raw_string = @raw_received.string
48
- if headers_end_index = raw_string.index(separator)
49
- raw_string[0...(headers_end_index + separator.length)]
50
- else
51
- raw_string
52
- end
53
- end
54
- end
55
-
56
- module Net
57
- class BufferedIO
58
- private
59
-
60
- def rbuf_consume(len)
61
- s = @rbuf.slice!(0, len)
62
- if @debug_output
63
- @debug_output << %Q[-> #{s.dump}\n]
64
- @debug_output.received(s) if @debug_output.respond_to?(:received)
65
- end
66
- s
67
- end
68
-
69
- def write0(str)
70
- if @debug_output
71
- @debug_output << str.dump
72
- @debug_output.sent(str) if @debug_output.respond_to?(:sent)
73
- end
74
- len = @io.write(str)
75
- @written_bytes += len
76
- len
77
- end
78
- end
79
- end
5
+ require 'raw_net_capture/raw_net_capture'
6
+ require 'raw_net_capture/raw_http_capture'
7
+ require 'raw_net_capture/net/buffered_io'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raw_net_capture
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Grossman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-26 00:00:00.000000000 Z
12
+ date: 2023-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: appraisal
@@ -62,6 +62,9 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - lib/raw_net_capture.rb
65
+ - lib/raw_net_capture/net/buffered_io.rb
66
+ - lib/raw_net_capture/raw_http_capture.rb
67
+ - lib/raw_net_capture/raw_net_capture.rb
65
68
  homepage: https://github.com/zendesk/raw_net_capture
66
69
  licenses:
67
70
  - Apache License Version 2.0
@@ -81,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
84
  - !ruby/object:Gem::Version
82
85
  version: '0'
83
86
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.2.2
87
+ rubygems_version: 3.0.3.1
86
88
  signing_key:
87
89
  specification_version: 4
88
90
  summary: Capture raw data in net debug_output