opensaz 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4979ad8cc2481fa517bd078df7ae0a3aa78e26a6
4
- data.tar.gz: 7de2ec6e3fe35b069a7d8a3a782502a5c26f89a9
3
+ metadata.gz: 58a4e453168101db656b77545dcd42edcb7d253a
4
+ data.tar.gz: cd5f9e8e1300ce96db21915b4eb40c75b31a7f72
5
5
  SHA512:
6
- metadata.gz: 08a5a655f189056594ff71045f95a575b1f04d163b8c718249a1985ca5a7d4a6b8f3bcaffc089a0788add37210410d76bce574997752586297448e97b8639fa5
7
- data.tar.gz: 6a5838266ee4714aa24c1ef05a7be369f0ca0ed72cb1af34e711fff34692bfe4d617ddb067c70817ddf459898d67bad84616532c56b9c707da6b1e2e64bfee76
6
+ metadata.gz: de553275d34eb598681599a01428edcab7da5509859c33cf93a5b6b9f57ef294f97cef40cd8b9f23d08ed8bdc71414a2d852b20d8fe8bf7e451731a460463ab9
7
+ data.tar.gz: 1789a11d8d3a3f98d89fdc476bf885080dce88aa6fafd70b3533577132bfe6dd173c3b77eb98cb7cc024b3cc2a5f85942d28c545aca6b917c4b9ffcd3322d56a
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 TODO: Write your name
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,120 +1,109 @@
1
- # Opensaz
2
-
3
- This is my first serious repo.!
4
-
5
- It's a Ruby Gem.
6
-
7
- It's used to read .saz file(generated by Fiddler, consist of HTTP requests and responses).
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- ```ruby
14
- gem 'opensaz'
15
- ```
16
-
17
- And then execute:
18
-
19
- $ bundle
20
-
21
- Or install it yourself as:
22
-
23
- $ gem install opensaz
24
-
25
- ## Usage
26
-
27
- #### Read .saz file
28
-
29
- A .saz file is simply a compressed file. You can extract it with 7zip. The folder structure and content after extraction are very clear.
30
-
31
- When you read a .saz file, Opensaz will immediately extract it to the location where the execution happens.
32
-
33
- ```ruby
34
- # will create folder like https_e5125274177355d294051e92098a2e58
35
- a = Opensaz.read("/Users/keegoo/workspace/https.saz")
36
- ```
37
-
38
- #### Packages
39
-
40
- A `package` is an HTTP interaction(request and response) between client and server.
41
-
42
- Typically a `package` consist of `id`, `comment`, `request` and `response`.
43
-
44
- id: is the number in the first column of packages-list in Fiddler UI.
45
- comment: in Fiddler UI, you can add comment for each package.
46
- request: a HTTP request.
47
- response: a HTTP response.
48
-
49
- ```ruby
50
- require 'opensaz'
51
-
52
- a = Opensaz.read("/Users/keegoo/workspace/entity.saz")
53
-
54
- a.packages.each do |x|
55
- puts x.id
56
- puts x.comment
57
- puts x.request.headers[:path]
58
- puts x.request.headers[:method]
59
- puts x.request.headers[:content_type]
60
- puts x.request.body
61
-
62
- puts x.response.headers
63
- puts x.response.body
64
- end
65
- ```
66
-
67
- As a `package` is either HTTP or HTTPS protocol, you could pass :http or :https to filter it.
68
-
69
- It support :http, :https and :all(default value).
70
-
71
- ```ruby
72
- a.packages(:http).each do |x|
73
- # do anything
74
- end
75
- ```
76
-
77
- You could use Ruby build-in methods `select` to do some filtering.
78
-
79
- ```ruby
80
- a.packages.select{|x|x.comment =~ /some import message/}
81
-
82
- a.packages.select{|x|x.request.headers[:content_type] == "text/xml"}
83
-
84
- a.packages.select{|x|x.request.headers[:path].end_with?("api/batch")}
85
-
86
- # list goes on ...
87
- ```
88
-
89
- #### headers key name
90
-
91
- Headers of both request and response have many [fields](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields).
92
-
93
- `package.request.headers` is a hash. The keys is simply fields name of request header, but with a bit modification.
94
-
95
- e.g.:
96
-
97
- Accept => :accept
98
- Accept-Charset => :accept_charset
99
- Cookie => :cookie
100
- ...
101
-
102
- Same with response headers.
103
-
104
- If a key(field) doesn't exist, it will be `x.request.headers[:weird] = nil` which is how hash works in Ruby.
105
-
106
- ## Development
107
-
108
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
109
-
110
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
111
-
112
- ## Contributing
113
-
114
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/opensaz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
115
-
116
-
117
- ## License
118
-
119
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
120
-
1
+ # Opensaz
2
+
3
+ This is my first serious repo.!
4
+
5
+ It's a Ruby Gem.
6
+
7
+ It's used to read .saz file(generated by [Fiddler](http://www.telerik.com/fiddler), consist of HTTP requests and responses).
8
+
9
+ ## Installation
10
+
11
+ $ gem install opensaz
12
+
13
+ ## Usage
14
+
15
+ #### Read .saz file
16
+
17
+ A .saz file is simply a compressed file. You can extract it with 7zip. The folder structure and content after extraction are very clear.
18
+
19
+ The first time when you call `Opensaz.read('any.saz')`, it will extract all the contents into folder `any_#{md5}`. The next time you run it, as `any_#{md5}` already exists(unless you remove it), this function will return the path directly instead of extracting the content again.
20
+
21
+
22
+ ```ruby
23
+ # will create folder like https_e5125274177355d294051e92098a2e58
24
+ a = Opensaz.read("/Users/keegoo/workspace/https.saz")
25
+ ```
26
+
27
+ #### Packages
28
+
29
+ A `package` is an HTTP interaction(request and response) between client and server.
30
+
31
+ Typically a `package` consist of `id`, `comment`, `request` and `response`.
32
+
33
+ id: is the number in the first column of packages-list in Fiddler UI.
34
+ comment: in Fiddler UI, you can add comment for each package.
35
+ request: a HTTP request.
36
+ response: a HTTP response.
37
+
38
+ ```ruby
39
+ require 'opensaz'
40
+
41
+ a = Opensaz.read("/Users/keegoo/workspace/entity.saz")
42
+
43
+ a.packages.each do |x|
44
+ puts x.id
45
+ puts x.comment
46
+ puts x.request.headers[:path]
47
+ puts x.request.headers[:method]
48
+ puts x.request.headers[:content_type]
49
+ puts x.request.body
50
+
51
+ puts x.response.headers
52
+ puts x.response.body
53
+ end
54
+ ```
55
+
56
+ As a `package` is either HTTP or HTTPS protocol, you could pass :http or :https to filter it.
57
+
58
+ It support :http, :https and :all(default value).
59
+
60
+ ```ruby
61
+ a.packages(:http).each do |x|
62
+ # do anything
63
+ end
64
+ ```
65
+
66
+ You could use Ruby build-in methods `select` to do some filtering.
67
+
68
+ ```ruby
69
+ a.packages.select{|x|x.comment =~ /some import message/}
70
+
71
+ a.packages.select{|x|x.request.headers[:content_type] == "text/xml"}
72
+
73
+ a.packages.select{|x|x.request.headers[:path].end_with?("api/batch")}
74
+
75
+ # list goes on ...
76
+ ```
77
+
78
+ #### headers key name
79
+
80
+ Headers of both request and response have many [fields](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields).
81
+
82
+ `package.request.headers` is a hash. The keys is simply fields name of request header, but with a bit modification.
83
+
84
+ e.g.:
85
+
86
+ Accept => :accept
87
+ Accept-Charset => :accept_charset
88
+ Cookie => :cookie
89
+ ...
90
+
91
+ Same with response headers.
92
+
93
+ If a key(field) doesn't exist, it will be `x.request.headers[:weird] = nil` which is how hash works in Ruby.
94
+
95
+ ## Development
96
+
97
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
98
+
99
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
100
+
101
+ ## Contributing
102
+
103
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/opensaz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
104
+
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
109
+
data/lib/opensaz.rb CHANGED
@@ -1,29 +1,29 @@
1
- require_relative "opensaz/builder"
2
- require_relative "opensaz/extractor"
3
- require_relative "opensaz/general_info"
4
- require_relative "opensaz/http_request"
5
- require_relative "opensaz/http_response"
6
- require_relative "opensaz/http_miscel"
7
- require_relative "opensaz/package"
8
- require_relative "opensaz/version"
9
-
10
- #a = Opensaz.read(saz_path)
11
-
12
-
13
-
14
- #a.basic_info[:destination]
15
- #a.basic_info[:number_of_requests]
16
- #a.basic_info[:hosts]
17
- #a.packages.each{|x| puts x.duration}
18
- #a.packages.each{|x| puts x.start_time}
19
- #a.packages.each{|x| puts x.comments}
20
- #a.packages.each{|x| puts x.request[:host]}
21
- #a.packages.each{|x| puts x.response[:version]}
22
-
23
- module Opensaz
24
-
25
- def self.read(saz_path)
26
- Builder.new(saz_path)
27
- end
28
-
29
- end
1
+ require_relative "opensaz/builder"
2
+ require_relative "opensaz/extractor"
3
+ require_relative "opensaz/general_info"
4
+ require_relative "opensaz/http_request"
5
+ require_relative "opensaz/http_response"
6
+ require_relative "opensaz/http_miscel"
7
+ require_relative "opensaz/package"
8
+ require_relative "opensaz/version"
9
+
10
+ #a = Opensaz.read(saz_path)
11
+
12
+
13
+
14
+ #a.basic_info[:destination]
15
+ #a.basic_info[:number_of_requests]
16
+ #a.basic_info[:hosts]
17
+ #a.packages.each{|x| puts x.duration}
18
+ #a.packages.each{|x| puts x.start_time}
19
+ #a.packages.each{|x| puts x.comments}
20
+ #a.packages.each{|x| puts x.request[:host]}
21
+ #a.packages.each{|x| puts x.response[:version]}
22
+
23
+ module Opensaz
24
+
25
+ def self.read(saz_path)
26
+ Builder.new(saz_path)
27
+ end
28
+
29
+ end
@@ -1,58 +1,58 @@
1
- module Opensaz
2
- class Builder
3
-
4
- attr_reader :raw_files
5
-
6
- def initialize(saz_path)
7
- @saz_path = saz_path
8
- @dest = nil
9
-
10
- @raw_files = get_raw_files
11
- @packages = get_packages
12
- end
13
-
14
- def packages(type = :all)
15
- case type
16
- when :http
17
- @packages.select{|x| not x.request.headers[:host].end_with?("443")}
18
- when :https
19
- @packages.select{|x| x.request.headers[:host].end_with?("443")}
20
- else
21
- @packages
22
- end
23
- end
24
-
25
- private
26
-
27
- # ============================
28
- # return a list of hash, e.g.:
29
- # [{
30
- # id: "2",
31
- # c: "raw/1_c.txt",
32
- # s: "raw/1_s.txt",
33
- # m: "raw/1_m.xml",
34
- # comment: "user login"
35
- # }, ...]
36
- def get_raw_files
37
- @dest ||= Extractor.new(@saz_path).unzip
38
- index_file = File.join(@dest, "_index.htm")
39
- raise "no such file: #{index_file}" unless File.exist?(index_file)
40
- GeneralInfo.new(File.read(index_file)).to_a
41
- end
42
-
43
- def get_packages
44
- pkgs = []
45
- @raw_files.each do |x|
46
- ahash = {
47
- dest: @dest,
48
- c: x[:c],
49
- s: x[:s],
50
- m: x[:m],
51
- comment: x[:comment]
52
- }
53
- pkgs.push(Package.new(x[:id], ahash))
54
- end
55
- pkgs
56
- end
57
- end
1
+ module Opensaz
2
+ class Builder
3
+
4
+ attr_reader :raw_files
5
+
6
+ def initialize(saz_path)
7
+ @saz_path = saz_path
8
+ @dest = nil
9
+
10
+ @raw_files = get_raw_files
11
+ @packages = get_packages
12
+ end
13
+
14
+ def packages(type = :all)
15
+ case type
16
+ when :http
17
+ @packages.select{|x| not x.request.headers[:host].end_with?("443")}
18
+ when :https
19
+ @packages.select{|x| x.request.headers[:host].end_with?("443")}
20
+ else
21
+ @packages
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # ============================
28
+ # return a list of hash, e.g.:
29
+ # [{
30
+ # id: "2",
31
+ # c: "raw/1_c.txt",
32
+ # s: "raw/1_s.txt",
33
+ # m: "raw/1_m.xml",
34
+ # comment: "user login"
35
+ # }, ...]
36
+ def get_raw_files
37
+ @dest ||= Extractor.new(@saz_path).unzip
38
+ index_file = File.join(@dest, "_index.htm")
39
+ raise "no such file: #{index_file}" unless File.exist?(index_file)
40
+ GeneralInfo.new(File.read(index_file)).to_a
41
+ end
42
+
43
+ def get_packages
44
+ pkgs = []
45
+ @raw_files.each do |x|
46
+ ahash = {
47
+ dest: @dest,
48
+ c: x[:c],
49
+ s: x[:s],
50
+ m: x[:m],
51
+ comment: x[:comment]
52
+ }
53
+ pkgs.push(Package.new(x[:id], ahash))
54
+ end
55
+ pkgs
56
+ end
57
+ end
58
58
  end
@@ -1,40 +1,42 @@
1
- require 'zip'
2
- require 'securerandom'
3
-
4
- module Opensaz
5
- class Extractor
6
- def initialize(saz_path)
7
- # saz_path should be absolute path
8
- raise "no such file: #{saz_path}" unless File.exist?(saz_path)
9
- @saz = saz_path
10
- end
11
-
12
- def unzip
13
- Extractor.unzip(@saz, destination)
14
- end
15
-
16
- private
17
-
18
- def destination
19
- File.join(Dir.pwd, filename)
20
- end
21
-
22
- def filename
23
- File.basename(@saz, ".*") + "_" + SecureRandom.hex
24
- end
25
-
26
- def self.unzip(file, destination)
27
- begin
28
- Zip::File.open(file) do |zip_file|
29
- zip_file.each do |f|
30
- fpath = File.join(destination, f.name)
31
- zip_file.extract(f, fpath) unless File.exist?(fpath)
32
- end
33
- end
34
- rescue Zip::Error => e
35
- raise e.message
36
- end
37
- destination
38
- end
39
- end
1
+ require 'zip'
2
+ require 'digest'
3
+ # require 'securerandom'
4
+
5
+ module Opensaz
6
+ class Extractor
7
+ def initialize(saz_path)
8
+ # saz_path should be absolute path
9
+ raise "no such file: #{saz_path}" unless File.exist?(saz_path)
10
+ @saz = saz_path
11
+ @md5 = Digest::MD5.hexdigest(File.read(@saz))
12
+ end
13
+
14
+ def unzip
15
+ File.exist?(destination) ? destination : Extractor.unzip(@saz, destination)
16
+ end
17
+
18
+ private
19
+
20
+ def destination
21
+ File.join(Dir.pwd, filename)
22
+ end
23
+
24
+ def filename
25
+ File.basename(@saz, ".*") + "_" + @md5
26
+ end
27
+
28
+ def self.unzip(file, destination)
29
+ begin
30
+ Zip::File.open(file) do |zip_file|
31
+ zip_file.each do |f|
32
+ fpath = File.join(destination, f.name)
33
+ zip_file.extract(f, fpath) unless File.exist?(fpath)
34
+ end
35
+ end
36
+ rescue Zip::Error => e
37
+ raise e.message
38
+ end
39
+ destination
40
+ end
41
+ end
40
42
  end
@@ -1,80 +1,80 @@
1
- require 'nokogiri'
2
-
3
- module Opensaz
4
- class GeneralInfo
5
- def initialize(content)
6
- @page = Nokogiri::HTML(content)
7
- end
8
-
9
- def to_a
10
- keys = [:id, :c, :s, :m, :comment]
11
- ary = []
12
- @page.css('tbody tr').each do |x|
13
- values = get_tbody_tr(x)
14
- tmp = (0...keys.size).map{ |i| [keys[i], values[i]] }.to_h
15
- ary.push(tmp)
16
- end
17
- ary
18
- end
19
-
20
- private
21
-
22
- # ============================
23
- # note, the output order should
24
- # be inline with
25
- # [:id, :c, :s, :m, :comment]
26
- def get_tbody_tr(tr_node)
27
- tds = tr_node.css('td')
28
-
29
- i = comment_column
30
- if i == 0
31
- # no comment found
32
- [tds[1].text] + seperate_c_s_m(tds[0]) + [nil]
33
- else
34
- comment = text_or_nil(tds[i-1].text)
35
- [tds[1].text] + seperate_c_s_m(tds[0]) + [comment]
36
- end
37
- end
38
-
39
- def seperate_c_s_m(a_node)
40
- a_node.css('a').map{|a| folder_platform_compatible(a["href"]) }
41
- end
42
-
43
- # ============================
44
- # get comment column
45
- # return a number, indicating which
46
- # "th" is the comment.
47
- # return 0 if could not find it
48
- def comment_column
49
- res = 0
50
- @page.css('thead tr th').each do |x|
51
- res += 1
52
- if x.text == "Comments"
53
- break
54
- end
55
- end
56
- return res
57
- end
58
-
59
- # ============================
60
- # return nil if empty.
61
- # return itself if not empty.
62
- def text_or_nil(comment)
63
- comment.length == 0 ? nil : comment
64
- end
65
-
66
- # ============================
67
- # "raw\\1_c.txt" is too windows specific
68
- # from
69
- # windows specific
70
- # too
71
- # platform compatible
72
- def folder_platform_compatible(win_path)
73
- res = ""
74
- win_path.split("\\").each do |f|
75
- res = File.join(res, f)
76
- end
77
- res[1..-1]
78
- end
79
- end
80
- end
1
+ require 'nokogiri'
2
+
3
+ module Opensaz
4
+ class GeneralInfo
5
+ def initialize(content)
6
+ @page = Nokogiri::HTML(content)
7
+ end
8
+
9
+ def to_a
10
+ keys = [:id, :c, :s, :m, :comment]
11
+ ary = []
12
+ @page.css('tbody tr').each do |x|
13
+ values = get_tbody_tr(x)
14
+ tmp = (0...keys.size).map{ |i| [keys[i], values[i]] }.to_h
15
+ ary.push(tmp)
16
+ end
17
+ ary
18
+ end
19
+
20
+ private
21
+
22
+ # ============================
23
+ # note, the output order should
24
+ # be inline with
25
+ # [:id, :c, :s, :m, :comment]
26
+ def get_tbody_tr(tr_node)
27
+ tds = tr_node.css('td')
28
+
29
+ i = comment_column
30
+ if i == 0
31
+ # no comment found
32
+ [tds[1].text] + seperate_c_s_m(tds[0]) + [nil]
33
+ else
34
+ comment = text_or_nil(tds[i-1].text)
35
+ [tds[1].text] + seperate_c_s_m(tds[0]) + [comment]
36
+ end
37
+ end
38
+
39
+ def seperate_c_s_m(a_node)
40
+ a_node.css('a').map{|a| folder_platform_compatible(a["href"]) }
41
+ end
42
+
43
+ # ============================
44
+ # get comment column
45
+ # return a number, indicating which
46
+ # "th" is the comment.
47
+ # return 0 if could not find it
48
+ def comment_column
49
+ res = 0
50
+ @page.css('thead tr th').each do |x|
51
+ res += 1
52
+ if x.text == "Comments"
53
+ break
54
+ end
55
+ end
56
+ return res
57
+ end
58
+
59
+ # ============================
60
+ # return nil if empty.
61
+ # return itself if not empty.
62
+ def text_or_nil(comment)
63
+ comment.length == 0 ? nil : comment
64
+ end
65
+
66
+ # ============================
67
+ # "raw\\1_c.txt" is too windows specific
68
+ # from
69
+ # windows specific
70
+ # too
71
+ # platform compatible
72
+ def folder_platform_compatible(win_path)
73
+ res = ""
74
+ win_path.split("\\").each do |f|
75
+ res = File.join(res, f)
76
+ end
77
+ res[1..-1]
78
+ end
79
+ end
80
+ end
@@ -1,50 +1,50 @@
1
- require 'nokogiri'
2
-
3
- module Opensaz
4
- class HTTPMiscel
5
- def initialize(xml_str)
6
- @xml = Nokogiri::XML(xml_str)
7
- end
8
-
9
- def timers
10
- timers_hash = {}
11
- @xml.xpath("/Session/SessionTimers").each do |node|
12
- timers_hash = {
13
- client_connected: node.attribute("ClientConnected").text,
14
- client_begin_request: node.attribute("ClientBeginRequest").text,
15
- got_request_headers: node.attribute("GotRequestHeaders").text,
16
- client_done_request: node.attribute("ClientDoneRequest").text,
17
- gateway_time: node.attribute("GatewayTime").text,
18
- dns_time: node.attribute("DNSTime").text,
19
- tcp_connect_time: node.attribute("TCPConnectTime").text,
20
- https_handshake_time: node.attribute("HTTPSHandshakeTime").text,
21
- server_connected: node.attribute("ServerConnected").text,
22
- fiddler_begin_request: node.attribute("FiddlerBeginRequest").text,
23
- server_got_request: node.attribute("ServerGotRequest").text,
24
- server_begin_response: node.attribute("ServerBeginResponse").text,
25
- got_response_headers: node.attribute("GotResponseHeaders").text,
26
- server_done_response: node.attribute("ServerDoneResponse").text,
27
- client_begin_response: node.attribute("ClientBeginResponse").text,
28
- client_done_response: node.attribute("ClientDoneResponse").text
29
- }
30
- end
31
- timers_hash
32
- end
33
-
34
- def flags
35
- flags_hash = {}
36
- @xml.xpath("/Session/SessionFlags/SessionFlag").each do |node|
37
- flags_hash.store(symbolize_it(node.attribute("N").text), node.attribute("V").text)
38
- end
39
- flags_hash
40
- end
41
-
42
- private
43
-
44
- def symbolize_it(str)
45
- # make it lower case
46
- # sub '-'' with '_'
47
- str.downcase.gsub('-', '_').to_sym
48
- end
49
- end
1
+ require 'nokogiri'
2
+
3
+ module Opensaz
4
+ class HTTPMiscel
5
+ def initialize(xml_str)
6
+ @xml = Nokogiri::XML(xml_str)
7
+ end
8
+
9
+ def timers
10
+ timers_hash = {}
11
+ @xml.xpath("/Session/SessionTimers").each do |node|
12
+ timers_hash = {
13
+ client_connected: node.attribute("ClientConnected").text,
14
+ client_begin_request: node.attribute("ClientBeginRequest").text,
15
+ got_request_headers: node.attribute("GotRequestHeaders").text,
16
+ client_done_request: node.attribute("ClientDoneRequest").text,
17
+ gateway_time: node.attribute("GatewayTime").text,
18
+ dns_time: node.attribute("DNSTime").text,
19
+ tcp_connect_time: node.attribute("TCPConnectTime").text,
20
+ https_handshake_time: node.attribute("HTTPSHandshakeTime").text,
21
+ server_connected: node.attribute("ServerConnected").text,
22
+ fiddler_begin_request: node.attribute("FiddlerBeginRequest").text,
23
+ server_got_request: node.attribute("ServerGotRequest").text,
24
+ server_begin_response: node.attribute("ServerBeginResponse").text,
25
+ got_response_headers: node.attribute("GotResponseHeaders").text,
26
+ server_done_response: node.attribute("ServerDoneResponse").text,
27
+ client_begin_response: node.attribute("ClientBeginResponse").text,
28
+ client_done_response: node.attribute("ClientDoneResponse").text
29
+ }
30
+ end
31
+ timers_hash
32
+ end
33
+
34
+ def flags
35
+ flags_hash = {}
36
+ @xml.xpath("/Session/SessionFlags/SessionFlag").each do |node|
37
+ flags_hash.store(symbolize_it(node.attribute("N").text), node.attribute("V").text)
38
+ end
39
+ flags_hash
40
+ end
41
+
42
+ private
43
+
44
+ def symbolize_it(str)
45
+ # make it lower case
46
+ # sub '-'' with '_'
47
+ str.downcase.gsub('-', '_').to_sym
48
+ end
49
+ end
50
50
  end
@@ -1,49 +1,49 @@
1
- module Opensaz
2
- class HTTPRequest
3
-
4
- CRLF = "\r\n"
5
- SEPERATOR = ": "
6
-
7
- def initialize(content)
8
- raise "request_str couldn't be nil" if content == nil
9
- @content = content
10
- end
11
-
12
- def headers
13
- first_line = headers_str.split(CRLF)[0]
14
- following_lines = headers_str.split(CRLF)[1..-1]
15
- get_request_line(first_line).merge(get_headers(following_lines))
16
- end
17
-
18
- def body
19
- str = @content.split(CRLF * 2)[1..-1].join(CRLF * 2)
20
- str == "" ? nil : str
21
- end
22
-
23
- private
24
-
25
- def headers_str
26
- @content.split(CRLF * 2)[0]
27
- end
28
-
29
- def get_request_line(str)
30
- # turn first line of headers into hash
31
- a = str.split(" ")
32
- {method: a[0], path: a[1], version: a[2]}
33
- end
34
-
35
- def get_headers(lines)
36
- # turn following lines of headers into hash
37
- lines.map do |x|
38
- a = x.split(SEPERATOR)
39
- [symbolize_it(a[0]), a[1]]
40
- end.to_h
41
- end
42
-
43
- def symbolize_it(str)
44
- # make it lower case
45
- # sub '-'' with '_'
46
- str.downcase.gsub('-', '_').to_sym
47
- end
48
- end
1
+ module Opensaz
2
+ class HTTPRequest
3
+
4
+ CRLF = "\r\n"
5
+ SEPERATOR = ": "
6
+
7
+ def initialize(content)
8
+ raise "request_str couldn't be nil" if content == nil
9
+ @content = content
10
+ end
11
+
12
+ def headers
13
+ first_line = headers_str.split(CRLF)[0]
14
+ following_lines = headers_str.split(CRLF)[1..-1]
15
+ get_request_line(first_line).merge(get_headers(following_lines))
16
+ end
17
+
18
+ def body
19
+ str = @content.split(CRLF * 2)[1..-1].join(CRLF * 2)
20
+ str == "" ? nil : str
21
+ end
22
+
23
+ private
24
+
25
+ def headers_str
26
+ @content.split(CRLF * 2)[0]
27
+ end
28
+
29
+ def get_request_line(str)
30
+ # turn first line of headers into hash
31
+ a = str.split(" ")
32
+ {method: a[0], path: a[1], version: a[2]}
33
+ end
34
+
35
+ def get_headers(lines)
36
+ # turn following lines of headers into hash
37
+ lines.map do |x|
38
+ a = x.split(SEPERATOR)
39
+ [symbolize_it(a[0]), a[1]]
40
+ end.to_h
41
+ end
42
+
43
+ def symbolize_it(str)
44
+ # make it lower case
45
+ # sub '-'' with '_'
46
+ str.downcase.gsub('-', '_').to_sym
47
+ end
48
+ end
49
49
  end
@@ -1,16 +1,16 @@
1
- module Opensaz
2
- class HTTPResponse < HTTPRequest
3
- def headers
4
- first_line = headers_str.split(CRLF)[0]
5
- following_lines = headers_str.split(CRLF)[1..-1]
6
- get_status_line(first_line).merge(get_headers(following_lines))
7
- end
8
-
9
- private
10
-
11
- def get_status_line(str)
12
- a = str.split(" ")
13
- {version: a[0], code: a[1], status: a[2]}
14
- end
15
- end
1
+ module Opensaz
2
+ class HTTPResponse < HTTPRequest
3
+ def headers
4
+ first_line = headers_str.split(CRLF)[0]
5
+ following_lines = headers_str.split(CRLF)[1..-1]
6
+ get_status_line(first_line).merge(get_headers(following_lines))
7
+ end
8
+
9
+ private
10
+
11
+ def get_status_line(str)
12
+ a = str.split(" ")
13
+ {version: a[0], code: a[1], status: a[2]}
14
+ end
15
+ end
16
16
  end
@@ -1,31 +1,31 @@
1
- module Opensaz
2
- class Package
3
- attr_reader :id, :request, :response, :comment
4
- def initialize(id, ahash)
5
- @id = id
6
- @comment = ahash[:comment]
7
-
8
- requestf = File.join(ahash[:dest], ahash[:c])
9
- responsef = File.join(ahash[:dest], ahash[:s])
10
-
11
- check_files(requestf, responsef)
12
-
13
- @request = HTTPRequest.new(str_in_file(requestf))
14
- @response = HTTPResponse.new(str_in_file(responsef))
15
- end
16
-
17
- private
18
-
19
- def check_files(*files)
20
- files.each{|x| raise "No such file: #{x}" unless File.exist?(x) }
21
- end
22
-
23
- def str_in_file(file)
24
- # "b" is important. It won't change line endings.
25
- f = File.open(file, "rb")
26
- content = f.read
27
- f.close
28
- return content
29
- end
30
- end
1
+ module Opensaz
2
+ class Package
3
+ attr_reader :id, :request, :response, :comment
4
+ def initialize(id, ahash)
5
+ @id = id
6
+ @comment = ahash[:comment]
7
+
8
+ requestf = File.join(ahash[:dest], ahash[:c])
9
+ responsef = File.join(ahash[:dest], ahash[:s])
10
+
11
+ check_files(requestf, responsef)
12
+
13
+ @request = HTTPRequest.new(str_in_file(requestf))
14
+ @response = HTTPResponse.new(str_in_file(responsef))
15
+ end
16
+
17
+ private
18
+
19
+ def check_files(*files)
20
+ files.each{|x| raise "No such file: #{x}" unless File.exist?(x) }
21
+ end
22
+
23
+ def str_in_file(file)
24
+ # "b" is important. It won't change line endings.
25
+ f = File.open(file, "rb")
26
+ content = f.read
27
+ f.close
28
+ return content
29
+ end
30
+ end
31
31
  end
@@ -1,3 +1,3 @@
1
- module Opensaz
2
- VERSION = "0.2.0"
3
- end
1
+ module Opensaz
2
+ VERSION = "0.3.0"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cong Yang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler