shopify-cli 1.3.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +2 -2
  3. data/.github/CONTRIBUTING.md +9 -1
  4. data/.github/PULL_REQUEST_TEMPLATE.md +10 -1
  5. data/.github/workflows/release.yml +61 -0
  6. data/.github/workflows/triage.yml +22 -0
  7. data/.gitignore +0 -1
  8. data/.rubocop.yml +61 -8
  9. data/.rubocop_todo.yml +11 -0
  10. data/.travis.yml +1 -0
  11. data/CHANGELOG.md +30 -0
  12. data/Gemfile +3 -2
  13. data/Gemfile.lock +39 -37
  14. data/README.md +39 -7
  15. data/RELEASING.md +19 -29
  16. data/Rakefile +2 -0
  17. data/dev.yml +2 -2
  18. data/docs/_config.yml +1 -18
  19. data/docs/app/node/commands/index.md +2 -80
  20. data/docs/app/node/index.md +2 -33
  21. data/docs/app/rails/commands/index.md +2 -78
  22. data/docs/app/rails/index.md +2 -34
  23. data/docs/core/index.md +2 -84
  24. data/docs/getting-started/index.md +2 -25
  25. data/docs/getting-started/install/index.md +1 -118
  26. data/docs/getting-started/migrate/index.md +2 -94
  27. data/docs/getting-started/uninstall/index.md +2 -35
  28. data/docs/getting-started/upgrade/index.md +2 -39
  29. data/docs/help/start-app/index.md +2 -4
  30. data/docs/index.md +2 -24
  31. data/install.sh +1 -1
  32. data/lib/project_types/extension/cli.rb +21 -11
  33. data/lib/project_types/extension/commands/extension_command.rb +2 -2
  34. data/lib/project_types/extension/features/argo.rb +117 -0
  35. data/lib/project_types/extension/forms/create.rb +2 -2
  36. data/lib/project_types/extension/models/specification.rb +35 -0
  37. data/lib/project_types/extension/models/specification_handlers/checkout_post_purchase.rb +19 -0
  38. data/lib/project_types/extension/models/specification_handlers/default.rb +67 -0
  39. data/lib/project_types/extension/models/specifications.rb +77 -0
  40. data/lib/project_types/extension/tasks/configure_features.rb +52 -0
  41. data/lib/project_types/extension/tasks/fetch_specifications.rb +38 -0
  42. data/lib/project_types/node/cli.rb +4 -1
  43. data/lib/project_types/node/commands/connect.rb +15 -0
  44. data/lib/project_types/node/commands/create.rb +10 -4
  45. data/lib/project_types/node/commands/generate.rb +2 -11
  46. data/lib/project_types/node/messages/messages.rb +16 -50
  47. data/lib/project_types/rails/cli.rb +4 -1
  48. data/lib/project_types/rails/commands/connect.rb +15 -0
  49. data/lib/project_types/rails/commands/create.rb +15 -12
  50. data/lib/project_types/rails/forms/create.rb +1 -1
  51. data/lib/project_types/rails/gem.rb +1 -1
  52. data/lib/project_types/rails/messages/messages.rb +8 -5
  53. data/lib/project_types/script/cli.rb +9 -5
  54. data/lib/project_types/script/commands/create.rb +6 -4
  55. data/lib/project_types/script/commands/enable.rb +12 -4
  56. data/lib/project_types/script/commands/push.rb +5 -13
  57. data/lib/project_types/script/config/extension_points.yml +17 -12
  58. data/lib/project_types/script/errors.rb +21 -0
  59. data/lib/project_types/script/forms/create.rb +26 -2
  60. data/lib/project_types/script/graphql/app_script_update_or_create.graphql +10 -1
  61. data/lib/project_types/script/layers/application/build_script.rb +18 -17
  62. data/lib/project_types/script/layers/application/create_script.rb +12 -10
  63. data/lib/project_types/script/layers/application/extension_points.rb +24 -0
  64. data/lib/project_types/script/layers/application/push_script.rb +18 -16
  65. data/lib/project_types/script/layers/domain/errors.rb +7 -0
  66. data/lib/project_types/script/layers/domain/extension_point.rb +62 -7
  67. data/lib/project_types/script/layers/domain/metadata.rb +55 -0
  68. data/lib/project_types/script/layers/domain/push_package.rb +25 -6
  69. data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +17 -52
  70. data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +42 -11
  71. data/lib/project_types/script/layers/infrastructure/errors.rb +16 -0
  72. data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +10 -4
  73. data/lib/project_types/script/layers/infrastructure/project_creator.rb +2 -1
  74. data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +25 -13
  75. data/lib/project_types/script/layers/infrastructure/rust_project_creator.rb +72 -0
  76. data/lib/project_types/script/layers/infrastructure/rust_task_runner.rb +59 -0
  77. data/lib/project_types/script/layers/infrastructure/script_service.rb +9 -1
  78. data/lib/project_types/script/layers/infrastructure/task_runner.rb +4 -3
  79. data/lib/project_types/script/messages/messages.rb +55 -4
  80. data/lib/project_types/script/script_project.rb +25 -16
  81. data/lib/project_types/script/ui/error_handler.rb +59 -1
  82. data/lib/project_types/theme/cli.rb +40 -0
  83. data/lib/project_types/theme/commands/connect.rb +54 -0
  84. data/lib/project_types/theme/commands/create.rb +48 -0
  85. data/lib/project_types/theme/commands/deploy.rb +38 -0
  86. data/lib/project_types/theme/commands/generate.rb +20 -0
  87. data/lib/project_types/theme/commands/generate/env.rb +79 -0
  88. data/lib/project_types/theme/commands/push.rb +55 -0
  89. data/lib/project_types/theme/commands/serve.rb +31 -0
  90. data/lib/project_types/theme/forms/connect.rb +34 -0
  91. data/lib/project_types/theme/forms/create.rb +22 -0
  92. data/lib/project_types/theme/messages/messages.rb +147 -0
  93. data/lib/project_types/theme/tasks/ensure_themekit_installed.rb +78 -0
  94. data/lib/project_types/theme/themekit.rb +113 -0
  95. data/lib/shopify-cli/admin_api.rb +42 -2
  96. data/lib/shopify-cli/api.rb +34 -33
  97. data/lib/shopify-cli/commands/config.rb +24 -0
  98. data/lib/shopify-cli/commands/connect.rb +32 -15
  99. data/lib/shopify-cli/commands/system.rb +10 -1
  100. data/lib/shopify-cli/context.rb +23 -2
  101. data/lib/shopify-cli/core/entry_point.rb +1 -1
  102. data/lib/shopify-cli/core/monorail.rb +6 -4
  103. data/lib/shopify-cli/feature.rb +0 -2
  104. data/lib/shopify-cli/http_request.rb +27 -0
  105. data/lib/shopify-cli/js_deps.rb +1 -1
  106. data/lib/shopify-cli/messages/messages.rb +31 -7
  107. data/lib/shopify-cli/method_object.rb +104 -0
  108. data/lib/shopify-cli/partners_api.rb +25 -3
  109. data/lib/shopify-cli/process_supervision.rb +1 -1
  110. data/lib/shopify-cli/project.rb +12 -8
  111. data/lib/shopify-cli/project_type.rb +18 -2
  112. data/lib/shopify-cli/resolve_constant.rb +25 -0
  113. data/lib/shopify-cli/result.rb +432 -0
  114. data/lib/shopify-cli/shopifolk.rb +87 -0
  115. data/lib/shopify-cli/task.rb +8 -0
  116. data/lib/shopify-cli/tasks/create_api_client.rb +13 -2
  117. data/lib/shopify-cli/tasks/ensure_env.rb +3 -0
  118. data/lib/shopify-cli/tasks/select_org_and_shop.rb +10 -5
  119. data/lib/shopify-cli/tunnel.rb +8 -2
  120. data/lib/shopify-cli/version.rb +1 -1
  121. data/lib/shopify_cli.rb +5 -1
  122. data/shopify.fish +1 -1
  123. data/shopify.sh +1 -1
  124. data/vendor/deps/cli-kit/REVISION +1 -1
  125. data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +2 -2
  126. data/vendor/deps/cli-kit/lib/cli/kit/system.rb +3 -3
  127. data/vendor/deps/cli-ui/REVISION +1 -1
  128. data/vendor/deps/cli-ui/lib/cli/ui.rb +26 -22
  129. data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +4 -6
  130. data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -3
  131. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_stack.rb +8 -9
  132. data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -1
  133. data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +1 -0
  134. data/vendor/deps/cli-ui/lib/cli/ui/printer.rb +15 -3
  135. data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +4 -11
  136. data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -5
  137. data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +10 -10
  138. data/vendor/deps/cli-ui/lib/cli/ui/version.rb +1 -1
  139. data/vendor/deps/cli-ui/lib/cli/ui/wrap.rb +56 -0
  140. data/vendor/deps/webrick/.gitignore +9 -0
  141. data/vendor/deps/webrick/Gemfile +3 -0
  142. data/vendor/deps/webrick/LICENSE.txt +22 -0
  143. data/vendor/deps/webrick/README.md +61 -0
  144. data/vendor/deps/webrick/Rakefile +10 -0
  145. data/vendor/deps/webrick/lib/webrick.rb +232 -0
  146. data/vendor/deps/webrick/lib/webrick/accesslog.rb +157 -0
  147. data/vendor/deps/webrick/lib/webrick/cgi.rb +313 -0
  148. data/vendor/deps/webrick/lib/webrick/compat.rb +36 -0
  149. data/vendor/deps/webrick/lib/webrick/config.rb +158 -0
  150. data/vendor/deps/webrick/lib/webrick/cookie.rb +172 -0
  151. data/vendor/deps/webrick/lib/webrick/htmlutils.rb +30 -0
  152. data/vendor/deps/webrick/lib/webrick/httpauth.rb +96 -0
  153. data/vendor/deps/webrick/lib/webrick/httpauth/authenticator.rb +117 -0
  154. data/vendor/deps/webrick/lib/webrick/httpauth/basicauth.rb +116 -0
  155. data/vendor/deps/webrick/lib/webrick/httpauth/digestauth.rb +395 -0
  156. data/vendor/deps/webrick/lib/webrick/httpauth/htdigest.rb +132 -0
  157. data/vendor/deps/webrick/lib/webrick/httpauth/htgroup.rb +97 -0
  158. data/vendor/deps/webrick/lib/webrick/httpauth/htpasswd.rb +158 -0
  159. data/vendor/deps/webrick/lib/webrick/httpauth/userdb.rb +53 -0
  160. data/vendor/deps/webrick/lib/webrick/httpproxy.rb +354 -0
  161. data/vendor/deps/webrick/lib/webrick/httprequest.rb +636 -0
  162. data/vendor/deps/webrick/lib/webrick/httpresponse.rb +564 -0
  163. data/vendor/deps/webrick/lib/webrick/https.rb +152 -0
  164. data/vendor/deps/webrick/lib/webrick/httpserver.rb +294 -0
  165. data/vendor/deps/webrick/lib/webrick/httpservlet.rb +23 -0
  166. data/vendor/deps/webrick/lib/webrick/httpservlet/abstract.rb +152 -0
  167. data/vendor/deps/webrick/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  168. data/vendor/deps/webrick/lib/webrick/httpservlet/cgihandler.rb +126 -0
  169. data/vendor/deps/webrick/lib/webrick/httpservlet/erbhandler.rb +88 -0
  170. data/vendor/deps/webrick/lib/webrick/httpservlet/filehandler.rb +552 -0
  171. data/vendor/deps/webrick/lib/webrick/httpservlet/prochandler.rb +47 -0
  172. data/vendor/deps/webrick/lib/webrick/httpstatus.rb +194 -0
  173. data/vendor/deps/webrick/lib/webrick/httputils.rb +512 -0
  174. data/vendor/deps/webrick/lib/webrick/httpversion.rb +76 -0
  175. data/vendor/deps/webrick/lib/webrick/log.rb +156 -0
  176. data/vendor/deps/webrick/lib/webrick/server.rb +381 -0
  177. data/vendor/deps/webrick/lib/webrick/ssl.rb +215 -0
  178. data/vendor/deps/webrick/lib/webrick/utils.rb +265 -0
  179. data/vendor/deps/webrick/lib/webrick/version.rb +18 -0
  180. data/vendor/deps/webrick/webrick.gemspec +74 -0
  181. metadata +77 -27
  182. data/docs/Gemfile +0 -5
  183. data/docs/Gemfile.lock +0 -258
  184. data/docs/_data/nav.yml +0 -35
  185. data/docs/_includes/footer.html +0 -15
  186. data/docs/_includes/head.html +0 -19
  187. data/docs/_includes/sidebar_nav.html +0 -22
  188. data/docs/_includes/toc.html +0 -112
  189. data/docs/_layouts/default.html +0 -79
  190. data/docs/css/docs.css +0 -157
  191. data/docs/images/header.png +0 -0
  192. data/docs/installing-ruby.md +0 -28
  193. data/lib/project_types/extension/features/argo/admin.rb +0 -20
  194. data/lib/project_types/extension/features/argo/base.rb +0 -129
  195. data/lib/project_types/extension/features/argo/checkout.rb +0 -20
  196. data/lib/project_types/extension/models/type.rb +0 -81
  197. data/lib/project_types/extension/models/types/checkout_post_purchase.rb +0 -23
  198. data/lib/project_types/extension/models/types/product_subscription.rb +0 -24
  199. data/lib/project_types/node/commands/generate/billing.rb +0 -39
  200. data/lib/project_types/node/commands/generate/page.rb +0 -59
  201. data/lib/project_types/node/commands/generate/webhook.rb +0 -37
  202. data/lib/project_types/script/layers/domain/script.rb +0 -18
  203. data/lib/project_types/script/layers/infrastructure/assemblyscript_tsconfig.rb +0 -38
  204. data/lib/project_types/script/layers/infrastructure/script_repository.rb +0 -59
  205. data/lib/project_types/script/templates/ts/as-pect.config.js +0 -27
  206. data/lib/project_types/script/templates/ts/as-pect.d.ts +0 -1
@@ -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
@@ -0,0 +1,313 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # cgi.rb -- Yet another CGI library
4
+ #
5
+ # Author: IPR -- Internet Programming with Ruby -- writers
6
+ # Copyright (c) 2003 Internet Programming with Ruby writers. All rights
7
+ # reserved.
8
+ #
9
+ # $Id$
10
+
11
+ require_relative "httprequest"
12
+ require_relative "httpresponse"
13
+ require_relative "config"
14
+ require "stringio"
15
+
16
+ module WEBrick
17
+
18
+ # A CGI library using WEBrick requests and responses.
19
+ #
20
+ # Example:
21
+ #
22
+ # class MyCGI < WEBrick::CGI
23
+ # def do_GET req, res
24
+ # res.body = 'it worked!'
25
+ # res.status = 200
26
+ # end
27
+ # end
28
+ #
29
+ # MyCGI.new.start
30
+
31
+ class CGI
32
+
33
+ # The CGI error exception class
34
+
35
+ CGIError = Class.new(StandardError)
36
+
37
+ ##
38
+ # The CGI configuration. This is based on WEBrick::Config::HTTP
39
+
40
+ attr_reader :config
41
+
42
+ ##
43
+ # The CGI logger
44
+
45
+ attr_reader :logger
46
+
47
+ ##
48
+ # Creates a new CGI interface.
49
+ #
50
+ # The first argument in +args+ is a configuration hash which would update
51
+ # WEBrick::Config::HTTP.
52
+ #
53
+ # Any remaining arguments are stored in the <code>@options</code> instance
54
+ # variable for use by a subclass.
55
+
56
+ def initialize(*args)
57
+ if defined?(MOD_RUBY)
58
+ unless ENV.has_key?("GATEWAY_INTERFACE")
59
+ Apache.request.setup_cgi_env
60
+ end
61
+ end
62
+ if %r{HTTP/(\d+\.\d+)} =~ ENV["SERVER_PROTOCOL"]
63
+ httpv = $1
64
+ end
65
+ @config = WEBrick::Config::HTTP.dup.update(
66
+ :ServerSoftware => ENV["SERVER_SOFTWARE"] || "null",
67
+ :HTTPVersion => HTTPVersion.new(httpv || "1.0"),
68
+ :RunOnCGI => true, # to detect if it runs on CGI.
69
+ :NPH => false # set true to run as NPH script.
70
+ )
71
+ if config = args.shift
72
+ @config.update(config)
73
+ end
74
+ @config[:Logger] ||= WEBrick::BasicLog.new($stderr)
75
+ @logger = @config[:Logger]
76
+ @options = args
77
+ end
78
+
79
+ ##
80
+ # Reads +key+ from the configuration
81
+
82
+ def [](key)
83
+ @config[key]
84
+ end
85
+
86
+ ##
87
+ # Starts the CGI process with the given environment +env+ and standard
88
+ # input and output +stdin+ and +stdout+.
89
+
90
+ def start(env=ENV, stdin=$stdin, stdout=$stdout)
91
+ sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
92
+ req = HTTPRequest.new(@config)
93
+ res = HTTPResponse.new(@config)
94
+ unless @config[:NPH] or defined?(MOD_RUBY)
95
+ def res.setup_header
96
+ unless @header["status"]
97
+ phrase = HTTPStatus::reason_phrase(@status)
98
+ @header["status"] = "#{@status} #{phrase}"
99
+ end
100
+ super
101
+ end
102
+ def res.status_line
103
+ ""
104
+ end
105
+ end
106
+
107
+ begin
108
+ req.parse(sock)
109
+ req.script_name = (env["SCRIPT_NAME"] || File.expand_path($0)).dup
110
+ req.path_info = (env["PATH_INFO"] || "").dup
111
+ req.query_string = env["QUERY_STRING"]
112
+ req.user = env["REMOTE_USER"]
113
+ res.request_method = req.request_method
114
+ res.request_uri = req.request_uri
115
+ res.request_http_version = req.http_version
116
+ res.keep_alive = req.keep_alive?
117
+ self.service(req, res)
118
+ rescue HTTPStatus::Error => ex
119
+ res.set_error(ex)
120
+ rescue HTTPStatus::Status => ex
121
+ res.status = ex.code
122
+ rescue Exception => ex
123
+ @logger.error(ex)
124
+ res.set_error(ex, true)
125
+ ensure
126
+ req.fixup
127
+ if defined?(MOD_RUBY)
128
+ res.setup_header
129
+ Apache.request.status_line = "#{res.status} #{res.reason_phrase}"
130
+ Apache.request.status = res.status
131
+ table = Apache.request.headers_out
132
+ res.header.each{|key, val|
133
+ case key
134
+ when /^content-encoding$/i
135
+ Apache::request.content_encoding = val
136
+ when /^content-type$/i
137
+ Apache::request.content_type = val
138
+ else
139
+ table[key] = val.to_s
140
+ end
141
+ }
142
+ res.cookies.each{|cookie|
143
+ table.add("Set-Cookie", cookie.to_s)
144
+ }
145
+ Apache.request.send_http_header
146
+ res.send_body(sock)
147
+ else
148
+ res.send_response(sock)
149
+ end
150
+ end
151
+ end
152
+
153
+ ##
154
+ # Services the request +req+ which will fill in the response +res+. See
155
+ # WEBrick::HTTPServlet::AbstractServlet#service for details.
156
+
157
+ def service(req, res)
158
+ method_name = "do_" + req.request_method.gsub(/-/, "_")
159
+ if respond_to?(method_name)
160
+ __send__(method_name, req, res)
161
+ else
162
+ raise HTTPStatus::MethodNotAllowed,
163
+ "unsupported method `#{req.request_method}'."
164
+ end
165
+ end
166
+
167
+ ##
168
+ # Provides HTTP socket emulation from the CGI environment
169
+
170
+ class Socket # :nodoc:
171
+ include Enumerable
172
+
173
+ private
174
+
175
+ def initialize(config, env, stdin, stdout)
176
+ @config = config
177
+ @env = env
178
+ @header_part = StringIO.new
179
+ @body_part = stdin
180
+ @out_port = stdout
181
+ @out_port.binmode
182
+
183
+ @server_addr = @env["SERVER_ADDR"] || "0.0.0.0"
184
+ @server_name = @env["SERVER_NAME"]
185
+ @server_port = @env["SERVER_PORT"]
186
+ @remote_addr = @env["REMOTE_ADDR"]
187
+ @remote_host = @env["REMOTE_HOST"] || @remote_addr
188
+ @remote_port = @env["REMOTE_PORT"] || 0
189
+
190
+ begin
191
+ @header_part << request_line << CRLF
192
+ setup_header
193
+ @header_part << CRLF
194
+ @header_part.rewind
195
+ rescue Exception
196
+ raise CGIError, "invalid CGI environment"
197
+ end
198
+ end
199
+
200
+ def request_line
201
+ meth = @env["REQUEST_METHOD"] || "GET"
202
+ unless url = @env["REQUEST_URI"]
203
+ url = (@env["SCRIPT_NAME"] || File.expand_path($0)).dup
204
+ url << @env["PATH_INFO"].to_s
205
+ url = WEBrick::HTTPUtils.escape_path(url)
206
+ if query_string = @env["QUERY_STRING"]
207
+ unless query_string.empty?
208
+ url << "?" << query_string
209
+ end
210
+ end
211
+ end
212
+ # we cannot get real HTTP version of client ;)
213
+ httpv = @config[:HTTPVersion]
214
+ return "#{meth} #{url} HTTP/#{httpv}"
215
+ end
216
+
217
+ def setup_header
218
+ @env.each{|key, value|
219
+ case key
220
+ when "CONTENT_TYPE", "CONTENT_LENGTH"
221
+ add_header(key.gsub(/_/, "-"), value)
222
+ when /^HTTP_(.*)/
223
+ add_header($1.gsub(/_/, "-"), value)
224
+ end
225
+ }
226
+ end
227
+
228
+ def add_header(hdrname, value)
229
+ unless value.empty?
230
+ @header_part << hdrname << ": " << value << CRLF
231
+ end
232
+ end
233
+
234
+ def input
235
+ @header_part.eof? ? @body_part : @header_part
236
+ end
237
+
238
+ public
239
+
240
+ def peeraddr
241
+ [nil, @remote_port, @remote_host, @remote_addr]
242
+ end
243
+
244
+ def addr
245
+ [nil, @server_port, @server_name, @server_addr]
246
+ end
247
+
248
+ def gets(eol=LF, size=nil)
249
+ input.gets(eol, size)
250
+ end
251
+
252
+ def read(size=nil)
253
+ input.read(size)
254
+ end
255
+
256
+ def each
257
+ input.each{|line| yield(line) }
258
+ end
259
+
260
+ def eof?
261
+ input.eof?
262
+ end
263
+
264
+ def <<(data)
265
+ @out_port << data
266
+ end
267
+
268
+ def write(data)
269
+ @out_port.write(data)
270
+ end
271
+
272
+ def cert
273
+ return nil unless defined?(OpenSSL)
274
+ if pem = @env["SSL_SERVER_CERT"]
275
+ OpenSSL::X509::Certificate.new(pem) unless pem.empty?
276
+ end
277
+ end
278
+
279
+ def peer_cert
280
+ return nil unless defined?(OpenSSL)
281
+ if pem = @env["SSL_CLIENT_CERT"]
282
+ OpenSSL::X509::Certificate.new(pem) unless pem.empty?
283
+ end
284
+ end
285
+
286
+ def peer_cert_chain
287
+ return nil unless defined?(OpenSSL)
288
+ if @env["SSL_CLIENT_CERT_CHAIN_0"]
289
+ keys = @env.keys
290
+ certs = keys.sort.collect{|k|
291
+ if /^SSL_CLIENT_CERT_CHAIN_\d+$/ =~ k
292
+ if pem = @env[k]
293
+ OpenSSL::X509::Certificate.new(pem) unless pem.empty?
294
+ end
295
+ end
296
+ }
297
+ certs.compact
298
+ end
299
+ end
300
+
301
+ def cipher
302
+ return nil unless defined?(OpenSSL)
303
+ if cipher = @env["SSL_CIPHER"]
304
+ ret = [ cipher ]
305
+ ret << @env["SSL_PROTOCOL"]
306
+ ret << @env["SSL_CIPHER_USEKEYSIZE"]
307
+ ret << @env["SSL_CIPHER_ALGKEYSIZE"]
308
+ ret
309
+ end
310
+ end
311
+ end
312
+ end
313
+ end