suiren 24.04.04

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: 4e1c34467b9eba28fb90e1b2f3fa60073451aee64cbca79eca0c2141211a6ab3
4
+ data.tar.gz: 1cbb52b6fad8385d65f8085b3241b4ef85a284951567ae89f0442763dedde7e7
5
+ SHA512:
6
+ metadata.gz: 14026c13c6760ab4e56470b7e48870ec363e7caa05662f26ad6c6f65058fd9841bf00c5164c1cce7484c6e329d2dd745760a3586427693bdab450957d28ba4f3
7
+ data.tar.gz: 138a553254a7a0a3ba1a8cdca10e6ff201843a7f9a1fcbd6c05731318860d71a94170acac0772b63418d37b6f9298af295b50c68d81b185c54f3065c86b747cc
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
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
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 MURATA Mitsuharu
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,35 @@
1
+ # Suiren
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ 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/suiren`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/suiren.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/exe/suiren ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "suiren"
5
+ require "optparse"
6
+
7
+ @i18n = {
8
+ "en": {
9
+ "port": "Port number",
10
+ "version_info": "Displays version information",
11
+ "license_info": "Displays license information",
12
+ "bind_addr": "Set the bind address",
13
+ "content": "Set the content to reply to"
14
+ },
15
+ "ja": {
16
+ "port": "ポート番号",
17
+ "version_info": "バージョン情報を表示します",
18
+ "license_info": "ライセンス情報を表示します",
19
+ "bind_addr": "Bind アドレスを設定します",
20
+ "content": "返信するコンテンツを設定します"
21
+ }
22
+ }
23
+
24
+ def i18n(tag)
25
+ lang = :en
26
+ lang = :ja if ENV["LANG"].downcase.include?("ja")
27
+ @i18n[lang][tag]
28
+ end
29
+
30
+ opt = OptionParser.new
31
+ bind_addr = "localhost"
32
+ port = 8080
33
+ content = String.new
34
+
35
+ opt.on("-V", "--version", i18n(:version_info)) do |_v|
36
+ puts("#{File.basename($PROGRAM_NAME)} (#{Suiren::VERSION})")
37
+ exit(true)
38
+ end
39
+
40
+ opt.on("--license", i18n(:license_info)) do |_v|
41
+ puts(Suiren::COPYRIGHT)
42
+ exit(true)
43
+ end
44
+
45
+ opt.on("--bind-address [Bind Address]", i18n(:bind_addr)) do |addr|
46
+ bind_addr = addr
47
+ end
48
+
49
+ opt.on("-p [Port]", "--port", i18n(:port)) do |p|
50
+ port = p.to_i
51
+ end
52
+
53
+ opt.on("-c [Content]", "--content", i18n(:content)) do |cont|
54
+ content = cont
55
+ end
56
+
57
+ begin
58
+ opt.parse!(ARGV)
59
+ rescue OptionParser::InvalidOption
60
+ warn(comment(:option_not_appropriate))
61
+ exit(false)
62
+ end
63
+
64
+ Suiren::Suiren.new(bind_addr, port, content: content)
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Suiren
4
+ VERSION = "24.04.04"
5
+
6
+ COPYRIGHT = <<~COPYRIGHT_TEXT
7
+ The MIT License (MIT)
8
+
9
+ Copyright (c) 2024 MURATA Mitsuharu
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in
19
+ all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
+ THE SOFTWARE.
28
+ COPYRIGHT_TEXT
29
+ end
data/lib/suiren.rb ADDED
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "suiren/version"
4
+ require "socket"
5
+ require "json"
6
+ require "stringio"
7
+
8
+ module Suiren
9
+ class Error < StandardError; end
10
+
11
+ class Suiren # rubocop:disable Style/Documentation
12
+ def initialize(host, port, content: "") # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
13
+ server = TCPServer.new(host, port)
14
+ puts("サーバーが http://#{host}:#{port} で実行中です\n\n")
15
+ uplen = 0
16
+
17
+ loop do # rubocop:disable Metrics/BlockLength
18
+ begin
19
+ client = server.accept
20
+ rescue Interrupt
21
+ exit true
22
+ end
23
+
24
+ http_text = client.readpartial(4096)
25
+ io = StringIO.new(http_text)
26
+ time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
27
+ request_line = io.gets
28
+
29
+ max_key_len = 0
30
+ max_value_len = 0
31
+ headers = {}
32
+ keys = []
33
+
34
+ puts("[#{time}]")
35
+ while (line = io.gets)
36
+ break if line.strip.empty?
37
+
38
+ match = line.match(/^(.+):\s(.+)$/)
39
+ break unless match
40
+
41
+ key = match[1]
42
+ keys.append(key)
43
+ value = match[2]
44
+ max_key_len = key.size if max_key_len < key.size
45
+ max_value_len = value.size if max_value_len < value.size
46
+ headers[key.strip] = value.strip
47
+ end
48
+
49
+ request_line_format = "%-#{max_key_len + max_value_len + 3}s"
50
+ puts "+#{"-" * (max_key_len + max_value_len + 5)}+"
51
+ puts "| #{request_line_format % request_line.chop} |"
52
+ key_format = "%-#{max_key_len}s"
53
+ value_format = "%-#{max_value_len}s"
54
+ border = "+#{"-" * (max_key_len + 2)}+#{"-" * (max_value_len + 2)}+"
55
+ puts border
56
+ keys.each do |key| # rubocop:disable Lint/ShadowingOuterLocalVariable
57
+ puts "| #{key_format % key} | #{value_format % headers[key]} |"
58
+ end
59
+ puts "#{border}\n"
60
+ body = "#{io.read}\n"
61
+ puts body
62
+ uplen = headers.size + 5 + body.lines.size
63
+
64
+ client.print "HTTP/1.1 200 OK\r\n"
65
+ client.print "Content-Type: text/plain; charset=\"UTF-8\"\r\n\r\n"
66
+ client.print("#{content}\r\n") unless content.empty?
67
+ client.close
68
+ end
69
+ end
70
+ end
71
+ end
data/sig/botan.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Suiren
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: suiren
3
+ version: !ruby/object:Gem::Version
4
+ version: 24.04.04
5
+ platform: ruby
6
+ authors:
7
+ - MURATA Mitsuharu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.21'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.21'
41
+ description: suiren is a command that displays the contents of http requests.
42
+ email:
43
+ - hikari.photon+dev@gmail.com
44
+ executables:
45
+ - suiren
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".rubocop.yml"
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - exe/suiren
54
+ - lib/suiren.rb
55
+ - lib/suiren/version.rb
56
+ - sig/botan.rbs
57
+ homepage: https://github.com/Himeyama/suiren
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/Himeyama/suiren
62
+ source_code_uri: https://github.com/Himeyama/suiren
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.6.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.5.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: suiren is a command that displays the contents of http requests.
82
+ test_files: []