http_sieve 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 240b2d9ae353affcfee36569e40e8edf0cc2f26dbaa1851af56dcb65e1f0ead3
4
+ data.tar.gz: f7bf570411f8e4a3c87479e1ba7a1165322f0868ac14792e84b773d38c066186
5
+ SHA512:
6
+ metadata.gz: 3daee1f447a396bd97d9b3fcb8f759b0bd8a95f89326f4b99be15572fee33c1fe6435cffa663f34f498a76dffa0afa48240229dc8a0925a266667a66adbfa1b0
7
+ data.tar.gz: 4b39b956be6c9caa847029f41dcd8553af9e0df692006c09def0f81bea43faf6e12c7147266ef8cf71377d24936031dfbbb4637bfd613f40e2c5d21cf1f59114
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in http_sieve.gemspec
6
+ gemspec
7
+
8
+
data/LICENSE.txt ADDED
@@ -0,0 +1,8 @@
1
+
2
+ Copyright (c) 2021 Sergio Romero
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # HttpSieve
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/http_sieve`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'http_sieve'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install http_sieve
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/http_sieve.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+
5
+ CLEAN.include ['**/.*.sw?', '**/*.gem', 'test/test.log']
6
+
7
+ task default: %i[test package]
8
+ task package: :clean
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.libs << 'lib' << 'test'
12
+ t.test_files = FileList['test/**/*_test.rb']
13
+ t.warning = false
14
+ t.verbose = false
15
+ end
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 "http_sieve"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/sieve ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
+
5
+ require "http_sieve"
6
+
7
+ lines = STDIN.read.split("\n")
8
+ total_lines = lines.size
9
+
10
+ lines.each_with_index do |url, i|
11
+ print "[#{i}/#{total_lines}] Processing #{url}\r"
12
+
13
+ Sieve::API.new.get(url) { |json| json }
14
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/http_sieve/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "http_sieve"
7
+ spec.version = HttpSieve::VERSION
8
+ spec.authors = ["Sergio Romero"]
9
+ spec.email = ["yo@sergioro.com"]
10
+
11
+ spec.summary = "HTTP response sieve"
12
+ spec.description = "Takes URLs on stdin, prints them to stdout if they return a 200 or 300 http status"
13
+ #spec.homepage = ""
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
+
18
+ #spec.metadata["homepage_uri"] = spec.homepage
19
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, checkout our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HttpSieve
4
+ VERSION = "0.1.0"
5
+ end
data/lib/http_sieve.rb ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env -S ruby -W0
2
+
3
+ require 'json'
4
+ require 'net/https'
5
+
6
+ # Takes URLs on stdin, prints them to stdout if they return a 200 or 300 http
7
+ # status.
8
+ #
9
+ # Inspired by https://github.com/tomnomnom/hacks/tree/master/anti-burl
10
+ #
11
+ # === Usage
12
+ #
13
+ # $ ./sieve.rb < domains.txt
14
+ # 301 https://google.com
15
+ # 200 https://www.google.com
16
+ # 200 https://example.com
17
+ #
18
+ module Sieve
19
+ attr_reader :uri
20
+
21
+ class API
22
+ class Error < StandardError; end
23
+
24
+ def get(url, params = {}, &block)
25
+ @uri = URI url
26
+ @uri.query = URI.encode_www_form(params) unless params.empty?
27
+ get = Net::HTTP::Get.new(@uri)
28
+
29
+ request(get, &block)
30
+ end
31
+
32
+ private
33
+
34
+ def https_options
35
+ if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
36
+ @uri = URI(proxy)
37
+ {
38
+ proxy_address: uri.hostname,
39
+ proxy_port: uri.port,
40
+ proxy_from_env: false,
41
+ use_ssl: true
42
+ }
43
+ else
44
+ if @uri.scheme == 'https'
45
+ { use_ssl: true }
46
+ else
47
+ {}
48
+ end
49
+ end
50
+ end
51
+
52
+ def request(req)
53
+ Net::HTTP.start(@uri.host, @uri.port, https_options) do |http|
54
+ response = http.request(req)
55
+
56
+ case response.code
57
+ when /2../
58
+ puts "#{response.code} #{@uri}"
59
+ when /3../
60
+ #puts "#{response.code} #{@uri}"
61
+ @redirects ||= 0
62
+ if @redirects < 4
63
+ get(response['location'])
64
+ else
65
+ @redirects = 0
66
+ end
67
+ else
68
+ end
69
+ end
70
+ rescue SocketError # TCP connection error.
71
+ rescue Errno::ECONNRESET # Connection reset by peer - SSL_connect ().
72
+ rescue OpenSSL::SSL::SSLError
73
+ rescue Net::OpenTimeout
74
+ end
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: http_sieve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergio Romero
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Takes URLs on stdin, prints them to stdout if they return a 200 or 300
14
+ http status
15
+ email:
16
+ - yo@sergioro.com
17
+ executables:
18
+ - sieve
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - exe/sieve
29
+ - http_sieve.gemspec
30
+ - lib/http_sieve.rb
31
+ - lib/http_sieve/version.rb
32
+ homepage:
33
+ licenses: []
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.2.32
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: HTTP response sieve
54
+ test_files: []