har-net-http 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +22 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/har-net-http.gemspec +34 -0
- data/lib/har/net/http.rb +83 -0
- data/lib/har/net/http/version.rb +9 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d0df5b1f6701543c334307d5d34f16a15102a1b4eb896ec1278b311320bf2bea
|
4
|
+
data.tar.gz: 57f7661081856ccd6ed81b051e670531fd53bdb5031cd786043643c0d8813221
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87170d3b023a77ad530b3698199e5773e5d58fdcc2651cac0cbedd752bd147e5de9db1e3f08b13acdb9c69b2239167efe1461e24a2be4157b782bf34fc28b278
|
7
|
+
data.tar.gz: 5203d9cb082297fe3e3373c1831be7e4b71bbf11b6ab03d7d44954d5f798cd266fff643e248e9f773a2f27f77c7669e71143180363d62fe902513cd057c636ec
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.6.6
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Run the default task
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/BlockLength:
|
22
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
har-net-http (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
parallel (1.20.1)
|
12
|
+
parser (3.0.1.1)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.0.0)
|
15
|
+
rake (13.0.3)
|
16
|
+
regexp_parser (2.1.1)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.2)
|
31
|
+
rubocop (1.15.0)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 3.0.0.0)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
36
|
+
rexml
|
37
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
+
rubocop-ast (1.5.0)
|
41
|
+
parser (>= 3.0.1.1)
|
42
|
+
ruby-progressbar (1.11.0)
|
43
|
+
unicode-display_width (2.0.0)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
x86_64-darwin-19
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
har-net-http!
|
50
|
+
rake (~> 13.0)
|
51
|
+
rspec (~> 3.0)
|
52
|
+
rubocop (~> 1.7)
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
2.2.16
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Smartbear
|
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
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Har::Net::Http
|
2
|
+
|
3
|
+
This library captures HTTP(S) traffic made by `net/http` as [HAR](http://www.softwareishard.com/blog/har-12-spec/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'har-net-http'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install har-net-http
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To capture a HAR, load this library:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'har/net/http'
|
27
|
+
|
28
|
+
# Reset the har, so that future requests will create a new HAR
|
29
|
+
Har::Net::HTTP.har = nil
|
30
|
+
```
|
31
|
+
|
32
|
+
Then, [make some HTTP requests](https://docs.ruby-lang.org/en/master/Net/HTTP.html).
|
33
|
+
If you prefer, you can also make HTTP requests with higher level libraries such as
|
34
|
+
[faraday](https://lostisland.github.io/faraday/), [http.rb](https://github.com/httprb/http),
|
35
|
+
[rest-client](https://github.com/rest-client/rest-client), [httparty](https://github.com/jnunemaker/httparty)
|
36
|
+
or any other library that is built on top of Ruby's `net/http` library.
|
37
|
+
|
38
|
+
When you're done, capture the HAR:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
har = JSON.stringify(Har::Net::HTTP.har)
|
42
|
+
|
43
|
+
# Do what you want with it!
|
44
|
+
```
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
|
+
|
50
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cucumber/har-net-http.
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "har/net/http"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/har/net/http/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "har-net-http"
|
7
|
+
spec.version = Har::Net::HTTP::VERSION
|
8
|
+
spec.authors = ["Aslak Hellesøy"]
|
9
|
+
spec.email = ["aslak.hellesoy@smartbear.com"]
|
10
|
+
|
11
|
+
spec.summary = "Capture HAR files from net/http requests."
|
12
|
+
spec.homepage = "https://github.com/cucumber/har-net-http"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/cucumber/har-net-http"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/cucumber/har-net-http/blob/main/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
# Uncomment to register a new dependency of your gem
|
30
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
31
|
+
|
32
|
+
# For more information and examples about making a new gem, checkout our
|
33
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
34
|
+
end
|
data/lib/har/net/http.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require_relative "http/version"
|
5
|
+
|
6
|
+
module Har
|
7
|
+
module Net
|
8
|
+
module HTTP
|
9
|
+
class << self
|
10
|
+
attr_accessor :har
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Net
|
17
|
+
# Reopen and monkey-patch the request method to capture traffic
|
18
|
+
class HTTP
|
19
|
+
alias original_request request
|
20
|
+
|
21
|
+
def request(req, body = nil, &block)
|
22
|
+
start_time = Time.now
|
23
|
+
res = original_request(req, body, &block)
|
24
|
+
end_time = Time.now
|
25
|
+
duration = ((end_time.to_f - start_time.to_f) * 1000).round
|
26
|
+
|
27
|
+
har_entry = {
|
28
|
+
# https://gist.github.com/dstagner/193207fed46acf5b5bae
|
29
|
+
startedDateTime: start_time.round(10).iso8601(6),
|
30
|
+
time: duration,
|
31
|
+
request: {
|
32
|
+
method: req.method,
|
33
|
+
url: req.uri.to_s,
|
34
|
+
httpVersion: "HTTP/1.1",
|
35
|
+
cookies: [],
|
36
|
+
headers: req.to_hash.map { |name, value| { name: name, value: value, comment: "" } },
|
37
|
+
queryString: [],
|
38
|
+
headersSize: -1,
|
39
|
+
bodySize: -1
|
40
|
+
},
|
41
|
+
response: {
|
42
|
+
status: res.code,
|
43
|
+
statusText: res.message,
|
44
|
+
httpVersion: res.http_version,
|
45
|
+
cookies: [],
|
46
|
+
headers: [],
|
47
|
+
content: {},
|
48
|
+
redirectURL: "",
|
49
|
+
headersSize: 160,
|
50
|
+
bodySize: 850,
|
51
|
+
comment: ""
|
52
|
+
},
|
53
|
+
cache: {}, # Not applicable to server-side logging.
|
54
|
+
timings: {
|
55
|
+
send: 0, # Mandatory, but not applicable to server-side logging.
|
56
|
+
wait: duration,
|
57
|
+
receive: 0 # Mandatory, but not applicable to server-side logging.
|
58
|
+
}
|
59
|
+
}
|
60
|
+
har = ::Har::Net::HTTP.har ||= {
|
61
|
+
log: {
|
62
|
+
version: "1.2",
|
63
|
+
creator: {
|
64
|
+
name: "har-net-http",
|
65
|
+
version: ::Har::Net::HTTP::VERSION,
|
66
|
+
comment: ""
|
67
|
+
},
|
68
|
+
browser: {
|
69
|
+
name: RUBY_ENGINE,
|
70
|
+
version: RUBY_VERSION,
|
71
|
+
comment: ""
|
72
|
+
},
|
73
|
+
pages: [],
|
74
|
+
entries: [],
|
75
|
+
comment: ""
|
76
|
+
}
|
77
|
+
}
|
78
|
+
har[:log][:entries] << har_entry
|
79
|
+
|
80
|
+
res
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: har-net-http
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aslak Hellesøy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- aslak.hellesoy@smartbear.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".github/workflows/main.yml"
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- CHANGELOG.md
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- bin/console
|
31
|
+
- bin/setup
|
32
|
+
- har-net-http.gemspec
|
33
|
+
- lib/har/net/http.rb
|
34
|
+
- lib/har/net/http/version.rb
|
35
|
+
homepage: https://github.com/cucumber/har-net-http
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata:
|
39
|
+
homepage_uri: https://github.com/cucumber/har-net-http
|
40
|
+
source_code_uri: https://github.com/cucumber/har-net-http
|
41
|
+
changelog_uri: https://github.com/cucumber/har-net-http/blob/main/CHANGELOG.md
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.5.0
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.0.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Capture HAR files from net/http requests.
|
61
|
+
test_files: []
|