opensaz 0.1.0 → 0.2.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 +4 -4
- data/README.md +78 -1
- data/lib/opensaz/builder.rb +19 -6
- data/lib/opensaz/general_info.rb +37 -2
- data/lib/opensaz/http_request.rb +2 -1
- data/lib/opensaz/package.rb +2 -2
- data/lib/opensaz/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4979ad8cc2481fa517bd078df7ae0a3aa78e26a6
|
4
|
+
data.tar.gz: 7de2ec6e3fe35b069a7d8a3a782502a5c26f89a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08a5a655f189056594ff71045f95a575b1f04d163b8c718249a1985ca5a7d4a6b8f3bcaffc089a0788add37210410d76bce574997752586297448e97b8639fa5
|
7
|
+
data.tar.gz: 6a5838266ee4714aa24c1ef05a7be369f0ca0ed72cb1af34e711fff34692bfe4d617ddb067c70817ddf459898d67bad84616532c56b9c707da6b1e2e64bfee76
|
data/README.md
CHANGED
@@ -24,7 +24,84 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
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.
|
28
105
|
|
29
106
|
## Development
|
30
107
|
|
data/lib/opensaz/builder.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Opensaz
|
2
2
|
class Builder
|
3
3
|
|
4
|
-
attr_reader :raw_files
|
4
|
+
attr_reader :raw_files
|
5
5
|
|
6
6
|
def initialize(saz_path)
|
7
7
|
@saz_path = saz_path
|
@@ -11,15 +11,27 @@ module Opensaz
|
|
11
11
|
@packages = get_packages
|
12
12
|
end
|
13
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
|
+
|
14
25
|
private
|
15
26
|
|
16
27
|
# ============================
|
17
28
|
# return a list of hash, e.g.:
|
18
29
|
# [{
|
19
|
-
# :
|
20
|
-
# :
|
21
|
-
# :
|
22
|
-
# :
|
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"
|
23
35
|
# }, ...]
|
24
36
|
def get_raw_files
|
25
37
|
@dest ||= Extractor.new(@saz_path).unzip
|
@@ -35,7 +47,8 @@ module Opensaz
|
|
35
47
|
dest: @dest,
|
36
48
|
c: x[:c],
|
37
49
|
s: x[:s],
|
38
|
-
m: x[:m]
|
50
|
+
m: x[:m],
|
51
|
+
comment: x[:comment]
|
39
52
|
}
|
40
53
|
pkgs.push(Package.new(x[:id], ahash))
|
41
54
|
end
|
data/lib/opensaz/general_info.rb
CHANGED
@@ -7,7 +7,7 @@ module Opensaz
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_a
|
10
|
-
keys = [:id, :c, :s, :m]
|
10
|
+
keys = [:id, :c, :s, :m, :comment]
|
11
11
|
ary = []
|
12
12
|
@page.css('tbody tr').each do |x|
|
13
13
|
values = get_tbody_tr(x)
|
@@ -19,15 +19,50 @@ module Opensaz
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
+
# ============================
|
23
|
+
# note, the output order should
|
24
|
+
# be inline with
|
25
|
+
# [:id, :c, :s, :m, :comment]
|
22
26
|
def get_tbody_tr(tr_node)
|
23
27
|
tds = tr_node.css('td')
|
24
|
-
|
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
|
25
37
|
end
|
26
38
|
|
27
39
|
def seperate_c_s_m(a_node)
|
28
40
|
a_node.css('a').map{|a| folder_platform_compatible(a["href"]) }
|
29
41
|
end
|
30
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
|
+
|
31
66
|
# ============================
|
32
67
|
# "raw\\1_c.txt" is too windows specific
|
33
68
|
# from
|
data/lib/opensaz/http_request.rb
CHANGED
data/lib/opensaz/package.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Opensaz
|
2
2
|
class Package
|
3
|
-
attr_reader :id, :request, :response, :
|
3
|
+
attr_reader :id, :request, :response, :comment
|
4
4
|
def initialize(id, ahash)
|
5
5
|
@id = id
|
6
|
+
@comment = ahash[:comment]
|
6
7
|
|
7
8
|
requestf = File.join(ahash[:dest], ahash[:c])
|
8
9
|
responsef = File.join(ahash[:dest], ahash[:s])
|
@@ -11,7 +12,6 @@ module Opensaz
|
|
11
12
|
|
12
13
|
@request = HTTPRequest.new(str_in_file(requestf))
|
13
14
|
@response = HTTPResponse.new(str_in_file(responsef))
|
14
|
-
# @miscel = HTTPMiscel.new(File.read(files[2]))
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
data/lib/opensaz/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,7 +98,7 @@ files:
|
|
98
98
|
- lib/opensaz/http_response.rb
|
99
99
|
- lib/opensaz/package.rb
|
100
100
|
- lib/opensaz/version.rb
|
101
|
-
homepage:
|
101
|
+
homepage: https://github.com/keegoo/opensaz
|
102
102
|
licenses:
|
103
103
|
- MIT
|
104
104
|
metadata: {}
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.6.
|
121
|
+
rubygems_version: 2.6.10
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: a handy tool to read from .saz file.
|