raw_net_capture 1.1.0 → 2.0.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
2
  SHA1:
3
- metadata.gz: 1d6cf8bbc933a2477cb83cbcb3d6dcbfdd24a31d
4
- data.tar.gz: 2f5ed8a2ffa6af154039ea1d2ec27ee6ec255a58
3
+ metadata.gz: 0cddcb536ac8cc22edf1b0b2605deb406f783019
4
+ data.tar.gz: 59abcb2f70e8f5e61a7958bd867ab4107c8aaf02
5
5
  SHA512:
6
- metadata.gz: aea4d1138a7f2cdd04a8675f6975011218069e74fd5fa35078389c158a7b1dafffd5c2e18a80dc857a4d221fe6065381dd892e032ecf6eb9e7c51ff1634f8f52
7
- data.tar.gz: e5948bcdf2da1be5915bd72ac32458ab2ecf5e95cba15fbd07e41a9b5add9cc3dbe7189d6200f987deffb6aa430b709f9a031268c57064b25afc3b7099c4cc80
6
+ metadata.gz: cb2a51061d463901d575be9384a734838cbcbaa925b20046936a321cc1c739030a1bab8381d242bbd3023db056dc7233bdf853b7029deee7aa24fc7893239250
7
+ data.tar.gz: aa6cd0a9fc9bbb80f6045417b4bcf5a59ef7046bbad8020899bdc92cbfac9f6f927c9162d3ef31f83002880294103ce0775876ec7a619a79906e40c059c6d724
@@ -1,79 +1,5 @@
1
1
  # encoding: utf-8
2
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
- 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
3
+ require 'raw_net_capture/raw_net_capture'
4
+ require 'raw_net_capture/raw_http_capture'
5
+ require 'raw_net_capture/net/buffered_io'
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ module Net
4
+ class BufferedIO
5
+ private
6
+
7
+ def rbuf_consume(len)
8
+ str = @rbuf.slice!(0, len)
9
+ if @debug_output
10
+ @debug_output << %Q[-> #{str.dump}\n]
11
+ @debug_output.received(str) if @debug_output.respond_to?(:received)
12
+ end
13
+ str
14
+ end
15
+
16
+ def write0(str)
17
+ if @debug_output
18
+ @debug_output << str.dump
19
+ @debug_output.sent(str) if @debug_output.respond_to?(:sent)
20
+ end
21
+
22
+ len = @io.write(str)
23
+ @written_bytes += len
24
+ len
25
+ end
26
+ end
27
+ 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
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.0.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: 2015-02-25 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