shopify-cli 1.5.0 → 1.6.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.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +1 -0
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +9 -0
  5. data/README.md +39 -7
  6. data/Rakefile +2 -0
  7. data/dev.yml +2 -2
  8. data/docs/_config.yml +1 -18
  9. data/docs/app/node/commands/index.md +2 -80
  10. data/docs/app/node/index.md +2 -33
  11. data/docs/app/rails/commands/index.md +2 -78
  12. data/docs/app/rails/index.md +2 -34
  13. data/docs/core/index.md +2 -84
  14. data/docs/getting-started/index.md +2 -25
  15. data/docs/getting-started/install/index.md +1 -118
  16. data/docs/getting-started/migrate/index.md +2 -94
  17. data/docs/getting-started/uninstall/index.md +2 -35
  18. data/docs/getting-started/upgrade/index.md +2 -39
  19. data/docs/help/start-app/index.md +2 -4
  20. data/docs/index.md +2 -24
  21. data/install.sh +1 -1
  22. data/lib/project_types/extension/cli.rb +19 -10
  23. data/lib/project_types/extension/commands/extension_command.rb +2 -2
  24. data/lib/project_types/extension/features/argo.rb +117 -0
  25. data/lib/project_types/extension/forms/create.rb +2 -2
  26. data/lib/project_types/extension/models/specification.rb +35 -0
  27. data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +19 -0
  28. data/lib/project_types/extension/models/specification_handlers/default.rb +67 -0
  29. data/lib/project_types/extension/models/specifications.rb +77 -0
  30. data/lib/project_types/extension/tasks/configure_features.rb +52 -0
  31. data/lib/project_types/extension/tasks/fetch_specifications.rb +38 -0
  32. data/lib/project_types/node/commands/create.rb +3 -1
  33. data/lib/project_types/node/commands/generate.rb +2 -11
  34. data/lib/project_types/node/messages/messages.rb +9 -44
  35. data/lib/project_types/rails/commands/create.rb +8 -9
  36. data/lib/project_types/rails/forms/create.rb +1 -1
  37. data/lib/project_types/rails/gem.rb +1 -1
  38. data/lib/project_types/rails/messages/messages.rb +1 -1
  39. data/lib/project_types/script/cli.rb +7 -4
  40. data/lib/project_types/script/commands/create.rb +6 -4
  41. data/lib/project_types/script/commands/push.rb +5 -13
  42. data/lib/project_types/script/config/extension_points.yml +9 -5
  43. data/lib/project_types/script/errors.rb +17 -0
  44. data/lib/project_types/script/forms/create.rb +26 -2
  45. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +10 -1
  46. data/lib/project_types/script/layers/application/build_script.rb +9 -4
  47. data/lib/project_types/script/layers/application/create_script.rb +12 -10
  48. data/lib/project_types/script/layers/application/extension_points.rb +24 -0
  49. data/lib/project_types/script/layers/application/push_script.rb +18 -16
  50. data/lib/project_types/script/layers/domain/errors.rb +4 -0
  51. data/lib/project_types/script/layers/domain/extension_point.rb +62 -6
  52. data/lib/project_types/script/layers/domain/metadata.rb +55 -0
  53. data/lib/project_types/script/layers/domain/push_package.rb +25 -6
  54. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +6 -6
  55. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +16 -6
  56. data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +10 -4
  57. data/lib/project_types/script/layers/infrastructure/project_creator.rb +2 -1
  58. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +25 -13
  59. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +72 -0
  60. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +59 -0
  61. data/lib/project_types/script/layers/infrastructure/script_service.rb +7 -1
  62. data/lib/project_types/script/layers/infrastructure/task_runner.rb +4 -3
  63. data/lib/project_types/script/messages/messages.rb +39 -8
  64. data/lib/project_types/script/script_project.rb +25 -16
  65. data/lib/project_types/script/ui/error_handler.rb +34 -1
  66. data/lib/project_types/theme/cli.rb +40 -0
  67. data/lib/project_types/theme/commands/connect.rb +54 -0
  68. data/lib/project_types/theme/commands/create.rb +48 -0
  69. data/lib/project_types/theme/commands/deploy.rb +38 -0
  70. data/lib/project_types/theme/commands/generate.rb +20 -0
  71. data/lib/project_types/theme/commands/generate/env.rb +79 -0
  72. data/lib/project_types/theme/commands/push.rb +55 -0
  73. data/lib/project_types/theme/commands/serve.rb +31 -0
  74. data/lib/project_types/theme/forms/connect.rb +34 -0
  75. data/lib/project_types/theme/forms/create.rb +22 -0
  76. data/lib/project_types/theme/messages/messages.rb +147 -0
  77. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +78 -0
  78. data/lib/project_types/theme/themekit.rb +113 -0
  79. data/lib/shopify-cli/admin_api.rb +42 -2
  80. data/lib/shopify-cli/api.rb +27 -24
  81. data/lib/shopify-cli/commands/system.rb +1 -1
  82. data/lib/shopify-cli/context.rb +23 -2
  83. data/lib/shopify-cli/feature.rb +0 -2
  84. data/lib/shopify-cli/http_request.rb +20 -8
  85. data/lib/shopify-cli/messages/messages.rb +6 -3
  86. data/lib/shopify-cli/method_object.rb +104 -0
  87. data/lib/shopify-cli/partners_api.rb +8 -2
  88. data/lib/shopify-cli/project_type.rb +1 -1
  89. data/lib/shopify-cli/resolve_constant.rb +25 -0
  90. data/lib/shopify-cli/result.rb +432 -0
  91. data/lib/shopify-cli/shopifolk.rb +3 -2
  92. data/lib/shopify-cli/tasks/select_org_and_shop.rb +6 -5
  93. data/lib/shopify-cli/tunnel.rb +7 -1
  94. data/lib/shopify-cli/version.rb +1 -1
  95. data/lib/shopify_cli.rb +4 -1
  96. data/shopify.fish +1 -1
  97. data/shopify.sh +1 -1
  98. data/vendor/deps/cli-kit/REVISION +1 -1
  99. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +2 -2
  100. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +3 -3
  101. data/vendor/deps/cli-ui/REVISION +1 -1
  102. data/vendor/deps/cli-ui/lib/cli/ui.rb +26 -22
  103. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +4 -6
  104. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -3
  105. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +8 -9
  106. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -1
  107. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +1 -0
  108. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +15 -3
  109. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +4 -11
  110. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -5
  111. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +10 -10
  112. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +1 -1
  113. data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +56 -0
  114. data/vendor/deps/webrick/.gitignore +9 -0
  115. data/vendor/deps/webrick/Gemfile +3 -0
  116. data/vendor/deps/webrick/LICENSE.txt +22 -0
  117. data/vendor/deps/webrick/README.md +61 -0
  118. data/vendor/deps/webrick/Rakefile +10 -0
  119. data/vendor/deps/webrick/lib/webrick.rb +232 -0
  120. data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
  121. data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
  122. data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
  123. data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
  124. data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
  125. data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
  126. data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
  127. data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
  128. data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
  129. data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
  130. data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
  131. data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
  132. data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
  133. data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
  134. data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
  135. data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
  136. data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
  137. data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
  138. data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
  139. data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
  140. data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
  141. data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  142. data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
  143. data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
  144. data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
  145. data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
  146. data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
  147. data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
  148. data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
  149. data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
  150. data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
  151. data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
  152. data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
  153. data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
  154. data/vendor/deps/webrick/webrick.gemspec +74 -0
  155. metadata +70 -26
  156. data/docs/Gemfile +0 -5
  157. data/docs/Gemfile.lock +0 -258
  158. data/docs/_data/nav.yml +0 -35
  159. data/docs/_includes/footer.html +0 -15
  160. data/docs/_includes/head.html +0 -19
  161. data/docs/_includes/sidebar_nav.html +0 -22
  162. data/docs/_includes/toc.html +0 -112
  163. data/docs/_layouts/default.html +0 -79
  164. data/docs/css/docs.css +0 -157
  165. data/docs/images/header.png +0 -0
  166. data/docs/installing-ruby.md +0 -28
  167. data/lib/project_types/extension/features/argo/admin.rb +0 -20
  168. data/lib/project_types/extension/features/argo/base.rb +0 -129
  169. data/lib/project_types/extension/features/argo/checkout.rb +0 -20
  170. data/lib/project_types/extension/models/type.rb +0 -81
  171. data/lib/project_types/extension/models/types/checkout_post_purchase.rb +0 -23
  172. data/lib/project_types/extension/models/types/product_subscription.rb +0 -24
  173. data/lib/project_types/node/commands/generate/billing.rb +0 -39
  174. data/lib/project_types/node/commands/generate/page.rb +0 -59
  175. data/lib/project_types/node/commands/generate/webhook.rb +0 -37
  176. data/lib/project_types/script/layers/domain/script.rb +0 -18
  177. data/lib/project_types/script/layers/infrastructure/script_repository.rb +0 -47
  178. data/lib/project_types/script/templates/ts/as-pect.config.js +0 -27
  179. data/lib/project_types/script/templates/ts/as-pect.d.ts +0 -1
@@ -23,17 +23,17 @@ module CLI
23
23
 
24
24
  def self.winsize
25
25
  @winsize ||= begin
26
- winsize = IO.console.winsize
27
- setup_winsize_trap
26
+ winsize = IO.console.winsize
27
+ setup_winsize_trap
28
28
 
29
- if winsize.any?(&:zero?)
30
- [DEFAULT_HEIGHT, DEFAULT_WIDTH]
31
- else
32
- winsize
33
- end
34
- rescue
35
- [DEFAULT_HEIGHT, DEFAULT_WIDTH]
36
- end
29
+ if winsize.any?(&:zero?)
30
+ [DEFAULT_HEIGHT, DEFAULT_WIDTH]
31
+ else
32
+ winsize
33
+ end
34
+ rescue
35
+ [DEFAULT_HEIGHT, DEFAULT_WIDTH]
36
+ end
37
37
  end
38
38
 
39
39
  def self.setup_winsize_trap
@@ -1,5 +1,5 @@
1
1
  module CLI
2
2
  module UI
3
- VERSION = "1.3.0"
3
+ VERSION = "1.4.0"
4
4
  end
5
5
  end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ require 'cli/ui'
3
+ require 'cli/ui/frame/frame_stack'
4
+ require 'cli/ui/frame/frame_style'
5
+
6
+ module CLI
7
+ module UI
8
+ class Wrap
9
+ def initialize(input)
10
+ @input = input
11
+ end
12
+
13
+ def wrap
14
+ max_width = Terminal.width - Frame.prefix_width
15
+ width = 0
16
+ final = []
17
+ # Create an alternation of format codes of parameter lengths 1-20, since + and {1,n} not allowed in lookbehind
18
+ format_codes = (1..20).map { |n| /\x1b\[[\d;]{#{n}}m/ }.join('|')
19
+ codes = ''
20
+ @input.split(/(?=\s|\x1b\[[\d;]+m|\r)|(?<=\s|#{format_codes})/).each do |token|
21
+ case token
22
+ when '\x1B[0?m'
23
+ codes = ''
24
+ final << token
25
+ when /\x1b\[[\d;]+m/
26
+ codes += token # Track in use format codes so that they are resent after frame coloring
27
+ final << token
28
+ when "\n"
29
+ final << "\n#{codes}"
30
+ width = 0
31
+ when /\s/
32
+ token_width = ANSI.printing_width(token)
33
+ if width + token_width <= max_width
34
+ final << token
35
+ width += token_width
36
+ else
37
+ final << "\n#{codes}"
38
+ width = 0
39
+ end
40
+ else
41
+ token_width = ANSI.printing_width(token)
42
+ if width + token_width <= max_width
43
+ final << token
44
+ width += token_width
45
+ else
46
+ final << "\n#{codes}"
47
+ final << token
48
+ width = token_width
49
+ end
50
+ end
51
+ end
52
+ final.join
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,61 @@
1
+ # Webrick
2
+
3
+ WEBrick is an HTTP server toolkit that can be configured as an HTTPS server, a proxy server, and a virtual-host server.
4
+
5
+ WEBrick features complete logging of both server operations and HTTP access.
6
+
7
+ WEBrick supports both basic and digest authentication in addition to algorithms not in RFC 2617.
8
+
9
+ A WEBrick server can be composed of multiple WEBrick servers or servlets to provide differing behavior on a per-host or per-path basis. WEBrick includes servlets for handling CGI scripts, ERB pages, Ruby blocks and directory listings.
10
+
11
+ WEBrick also includes tools for daemonizing a process and starting a process at a higher privilege level and dropping permissions.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'webrick'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install webrick
28
+
29
+ ## Usage
30
+
31
+ To create a new WEBrick::HTTPServer that will listen to connections on port 8000 and serve documents from the current user's public_html folder:
32
+
33
+ ```ruby
34
+ require 'webrick'
35
+
36
+ root = File.expand_path '~/public_html'
37
+ server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
38
+ ```
39
+
40
+ To run the server you will need to provide a suitable shutdown hook as
41
+ starting the server blocks the current thread:
42
+
43
+ ```ruby
44
+ trap 'INT' do server.shutdown end
45
+
46
+ server.start
47
+ ```
48
+
49
+ ## Development
50
+
51
+ 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.
52
+
53
+ 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).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and Patch are welcome on https://bugs.ruby-lang.org/.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test" << "test/lib"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/test_*.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,232 @@
1
+ # frozen_string_literal: false
2
+ ##
3
+ # = WEB server toolkit.
4
+ #
5
+ # WEBrick is an HTTP server toolkit that can be configured as an HTTPS server,
6
+ # a proxy server, and a virtual-host server. WEBrick features complete
7
+ # logging of both server operations and HTTP access. WEBrick supports both
8
+ # basic and digest authentication in addition to algorithms not in RFC 2617.
9
+ #
10
+ # A WEBrick server can be composed of multiple WEBrick servers or servlets to
11
+ # provide differing behavior on a per-host or per-path basis. WEBrick
12
+ # includes servlets for handling CGI scripts, ERB pages, Ruby blocks and
13
+ # directory listings.
14
+ #
15
+ # WEBrick also includes tools for daemonizing a process and starting a process
16
+ # at a higher privilege level and dropping permissions.
17
+ #
18
+ # == Security
19
+ #
20
+ # *Warning:* WEBrick is not recommended for production. It only implements
21
+ # basic security checks.
22
+ #
23
+ # == Starting an HTTP server
24
+ #
25
+ # To create a new WEBrick::HTTPServer that will listen to connections on port
26
+ # 8000 and serve documents from the current user's public_html folder:
27
+ #
28
+ # require 'webrick'
29
+ #
30
+ # root = File.expand_path '~/public_html'
31
+ # server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
32
+ #
33
+ # To run the server you will need to provide a suitable shutdown hook as
34
+ # starting the server blocks the current thread:
35
+ #
36
+ # trap 'INT' do server.shutdown end
37
+ #
38
+ # server.start
39
+ #
40
+ # == Custom Behavior
41
+ #
42
+ # The easiest way to have a server perform custom operations is through
43
+ # WEBrick::HTTPServer#mount_proc. The block given will be called with a
44
+ # WEBrick::HTTPRequest with request info and a WEBrick::HTTPResponse which
45
+ # must be filled in appropriately:
46
+ #
47
+ # server.mount_proc '/' do |req, res|
48
+ # res.body = 'Hello, world!'
49
+ # end
50
+ #
51
+ # Remember that +server.mount_proc+ must precede +server.start+.
52
+ #
53
+ # == Servlets
54
+ #
55
+ # Advanced custom behavior can be obtained through mounting a subclass of
56
+ # WEBrick::HTTPServlet::AbstractServlet. Servlets provide more modularity
57
+ # when writing an HTTP server than mount_proc allows. Here is a simple
58
+ # servlet:
59
+ #
60
+ # class Simple < WEBrick::HTTPServlet::AbstractServlet
61
+ # def do_GET request, response
62
+ # status, content_type, body = do_stuff_with request
63
+ #
64
+ # response.status = 200
65
+ # response['Content-Type'] = 'text/plain'
66
+ # response.body = 'Hello, World!'
67
+ # end
68
+ # end
69
+ #
70
+ # To initialize the servlet you mount it on the server:
71
+ #
72
+ # server.mount '/simple', Simple
73
+ #
74
+ # See WEBrick::HTTPServlet::AbstractServlet for more details.
75
+ #
76
+ # == Virtual Hosts
77
+ #
78
+ # A server can act as a virtual host for multiple host names. After creating
79
+ # the listening host, additional hosts that do not listen can be created and
80
+ # attached as virtual hosts:
81
+ #
82
+ # server = WEBrick::HTTPServer.new # ...
83
+ #
84
+ # vhost = WEBrick::HTTPServer.new :ServerName => 'vhost.example',
85
+ # :DoNotListen => true, # ...
86
+ # vhost.mount '/', ...
87
+ #
88
+ # server.virtual_host vhost
89
+ #
90
+ # If no +:DocumentRoot+ is provided and no servlets or procs are mounted on the
91
+ # main server it will return 404 for all URLs.
92
+ #
93
+ # == HTTPS
94
+ #
95
+ # To create an HTTPS server you only need to enable SSL and provide an SSL
96
+ # certificate name:
97
+ #
98
+ # require 'webrick'
99
+ # require 'webrick/https'
100
+ #
101
+ # cert_name = [
102
+ # %w[CN localhost],
103
+ # ]
104
+ #
105
+ # server = WEBrick::HTTPServer.new(:Port => 8000,
106
+ # :SSLEnable => true,
107
+ # :SSLCertName => cert_name)
108
+ #
109
+ # This will start the server with a self-generated self-signed certificate.
110
+ # The certificate will be changed every time the server is restarted.
111
+ #
112
+ # To create a server with a pre-determined key and certificate you can provide
113
+ # them:
114
+ #
115
+ # require 'webrick'
116
+ # require 'webrick/https'
117
+ # require 'openssl'
118
+ #
119
+ # cert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem'
120
+ # pkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem'
121
+ #
122
+ # server = WEBrick::HTTPServer.new(:Port => 8000,
123
+ # :SSLEnable => true,
124
+ # :SSLCertificate => cert,
125
+ # :SSLPrivateKey => pkey)
126
+ #
127
+ # == Proxy Server
128
+ #
129
+ # WEBrick can act as a proxy server:
130
+ #
131
+ # require 'webrick'
132
+ # require 'webrick/httpproxy'
133
+ #
134
+ # proxy = WEBrick::HTTPProxyServer.new :Port => 8000
135
+ #
136
+ # trap 'INT' do proxy.shutdown end
137
+ #
138
+ # See WEBrick::HTTPProxy for further details including modifying proxied
139
+ # responses.
140
+ #
141
+ # == Basic and Digest authentication
142
+ #
143
+ # WEBrick provides both Basic and Digest authentication for regular and proxy
144
+ # servers. See WEBrick::HTTPAuth, WEBrick::HTTPAuth::BasicAuth and
145
+ # WEBrick::HTTPAuth::DigestAuth.
146
+ #
147
+ # == WEBrick as a daemonized Web Server
148
+ #
149
+ # WEBrick can be run as a daemonized server for small loads.
150
+ #
151
+ # === Daemonizing
152
+ #
153
+ # To start a WEBrick server as a daemon simple run WEBrick::Daemon.start
154
+ # before starting the server.
155
+ #
156
+ # === Dropping Permissions
157
+ #
158
+ # WEBrick can be started as one user to gain permission to bind to port 80 or
159
+ # 443 for serving HTTP or HTTPS traffic then can drop these permissions for
160
+ # regular operation. To listen on all interfaces for HTTP traffic:
161
+ #
162
+ # sockets = WEBrick::Utils.create_listeners nil, 80
163
+ #
164
+ # Then drop privileges:
165
+ #
166
+ # WEBrick::Utils.su 'www'
167
+ #
168
+ # Then create a server that does not listen by default:
169
+ #
170
+ # server = WEBrick::HTTPServer.new :DoNotListen => true, # ...
171
+ #
172
+ # Then overwrite the listening sockets with the port 80 sockets:
173
+ #
174
+ # server.listeners.replace sockets
175
+ #
176
+ # === Logging
177
+ #
178
+ # WEBrick can separately log server operations and end-user access. For
179
+ # server operations:
180
+ #
181
+ # log_file = File.open '/var/log/webrick.log', 'a+'
182
+ # log = WEBrick::Log.new log_file
183
+ #
184
+ # For user access logging:
185
+ #
186
+ # access_log = [
187
+ # [log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
188
+ # ]
189
+ #
190
+ # server = WEBrick::HTTPServer.new :Logger => log, :AccessLog => access_log
191
+ #
192
+ # See WEBrick::AccessLog for further log formats.
193
+ #
194
+ # === Log Rotation
195
+ #
196
+ # To rotate logs in WEBrick on a HUP signal (like syslogd can send), open the
197
+ # log file in 'a+' mode (as above) and trap 'HUP' to reopen the log file:
198
+ #
199
+ # trap 'HUP' do log_file.reopen '/path/to/webrick.log', 'a+'
200
+ #
201
+ # == Copyright
202
+ #
203
+ # Author: IPR -- Internet Programming with Ruby -- writers
204
+ #
205
+ # Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
206
+ # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
207
+ # reserved.
208
+ #--
209
+ # $IPR: webrick.rb,v 1.12 2002/10/01 17:16:31 gotoyuzo Exp $
210
+
211
+ module WEBrick
212
+ end
213
+
214
+ require 'webrick/compat.rb'
215
+
216
+ require 'webrick/version.rb'
217
+ require 'webrick/config.rb'
218
+ require 'webrick/log.rb'
219
+ require 'webrick/server.rb'
220
+ require_relative 'webrick/utils.rb'
221
+ require 'webrick/accesslog'
222
+
223
+ require 'webrick/htmlutils.rb'
224
+ require 'webrick/httputils.rb'
225
+ require 'webrick/cookie.rb'
226
+ require 'webrick/httpversion.rb'
227
+ require 'webrick/httpstatus.rb'
228
+ require 'webrick/httprequest.rb'
229
+ require 'webrick/httpresponse.rb'
230
+ require 'webrick/httpserver.rb'
231
+ require 'webrick/httpservlet.rb'
232
+ require 'webrick/httpauth.rb'
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+ #--
3
+ # accesslog.rb -- Access log handling utilities
4
+ #
5
+ # Author: IPR -- Internet Programming with Ruby -- writers
6
+ # Copyright (c) 2002 keita yamaguchi
7
+ # Copyright (c) 2002 Internet Programming with Ruby writers
8
+ #
9
+ # $IPR: accesslog.rb,v 1.1 2002/10/01 17:16:32 gotoyuzo Exp $
10
+
11
+ module WEBrick
12
+
13
+ ##
14
+ # AccessLog provides logging to various files in various formats.
15
+ #
16
+ # Multiple logs may be written to at the same time:
17
+ #
18
+ # access_log = [
19
+ # [$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT],
20
+ # [$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT],
21
+ # ]
22
+ #
23
+ # server = WEBrick::HTTPServer.new :AccessLog => access_log
24
+ #
25
+ # Custom log formats may be defined. WEBrick::AccessLog provides a subset
26
+ # of the formatting from Apache's mod_log_config
27
+ # http://httpd.apache.org/docs/mod/mod_log_config.html#formats. See
28
+ # AccessLog::setup_params for a list of supported options
29
+
30
+ module AccessLog
31
+
32
+ ##
33
+ # Raised if a parameter such as %e, %i, %o or %n is used without fetching
34
+ # a specific field.
35
+
36
+ class AccessLogError < StandardError; end
37
+
38
+ ##
39
+ # The Common Log Format's time format
40
+
41
+ CLF_TIME_FORMAT = "[%d/%b/%Y:%H:%M:%S %Z]"
42
+
43
+ ##
44
+ # Common Log Format
45
+
46
+ COMMON_LOG_FORMAT = "%h %l %u %t \"%r\" %s %b"
47
+
48
+ ##
49
+ # Short alias for Common Log Format
50
+
51
+ CLF = COMMON_LOG_FORMAT
52
+
53
+ ##
54
+ # Referer Log Format
55
+
56
+ REFERER_LOG_FORMAT = "%{Referer}i -> %U"
57
+
58
+ ##
59
+ # User-Agent Log Format
60
+
61
+ AGENT_LOG_FORMAT = "%{User-Agent}i"
62
+
63
+ ##
64
+ # Combined Log Format
65
+
66
+ COMBINED_LOG_FORMAT = "#{CLF} \"%{Referer}i\" \"%{User-agent}i\""
67
+
68
+ module_function
69
+
70
+ # This format specification is a subset of mod_log_config of Apache:
71
+ #
72
+ # %a:: Remote IP address
73
+ # %b:: Total response size
74
+ # %e{variable}:: Given variable in ENV
75
+ # %f:: Response filename
76
+ # %h:: Remote host name
77
+ # %{header}i:: Given request header
78
+ # %l:: Remote logname, always "-"
79
+ # %m:: Request method
80
+ # %{attr}n:: Given request attribute from <tt>req.attributes</tt>
81
+ # %{header}o:: Given response header
82
+ # %p:: Server's request port
83
+ # %{format}p:: The canonical port of the server serving the request or the
84
+ # actual port or the client's actual port. Valid formats are
85
+ # canonical, local or remote.
86
+ # %q:: Request query string
87
+ # %r:: First line of the request
88
+ # %s:: Request status
89
+ # %t:: Time the request was received
90
+ # %T:: Time taken to process the request
91
+ # %u:: Remote user from auth
92
+ # %U:: Unparsed URI
93
+ # %%:: Literal %
94
+
95
+ def setup_params(config, req, res)
96
+ params = Hash.new("")
97
+ params["a"] = req.peeraddr[3]
98
+ params["b"] = res.sent_size
99
+ params["e"] = ENV
100
+ params["f"] = res.filename || ""
101
+ params["h"] = req.peeraddr[2]
102
+ params["i"] = req
103
+ params["l"] = "-"
104
+ params["m"] = req.request_method
105
+ params["n"] = req.attributes
106
+ params["o"] = res
107
+ params["p"] = req.port
108
+ params["q"] = req.query_string
109
+ params["r"] = req.request_line.sub(/\x0d?\x0a\z/o, '')
110
+ params["s"] = res.status # won't support "%>s"
111
+ params["t"] = req.request_time
112
+ params["T"] = Time.now - req.request_time
113
+ params["u"] = req.user || "-"
114
+ params["U"] = req.unparsed_uri
115
+ params["v"] = config[:ServerName]
116
+ params
117
+ end
118
+
119
+ ##
120
+ # Formats +params+ according to +format_string+ which is described in
121
+ # setup_params.
122
+
123
+ def format(format_string, params)
124
+ format_string.gsub(/\%(?:\{(.*?)\})?>?([a-zA-Z%])/){
125
+ param, spec = $1, $2
126
+ case spec[0]
127
+ when ?e, ?i, ?n, ?o
128
+ raise AccessLogError,
129
+ "parameter is required for \"#{spec}\"" unless param
130
+ (param = params[spec][param]) ? escape(param) : "-"
131
+ when ?t
132
+ params[spec].strftime(param || CLF_TIME_FORMAT)
133
+ when ?p
134
+ case param
135
+ when 'remote'
136
+ escape(params["i"].peeraddr[1].to_s)
137
+ else
138
+ escape(params["p"].to_s)
139
+ end
140
+ when ?%
141
+ "%"
142
+ else
143
+ escape(params[spec].to_s)
144
+ end
145
+ }
146
+ end
147
+
148
+ ##
149
+ # Escapes control characters in +data+
150
+
151
+ def escape(data)
152
+ data = data.gsub(/[[:cntrl:]\\]+/) {$&.dump[1...-1]}
153
+ data.untaint if RUBY_VERSION < '2.7'
154
+ data
155
+ end
156
+ end
157
+ end