ronin-web 0.3.0.rc1 → 1.0.0.beta2

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 (148) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.github/workflows/ruby.yml +31 -0
  4. data/.gitignore +13 -0
  5. data/.mailmap +1 -0
  6. data/.ruby-version +1 -0
  7. data/COPYING.txt +3 -3
  8. data/ChangeLog.md +115 -70
  9. data/Gemfile +42 -37
  10. data/README.md +160 -145
  11. data/Rakefile +12 -3
  12. data/bin/ronin-web +9 -17
  13. data/data/new/nokogiri.rb.erb +12 -0
  14. data/data/new/server.rb.erb +22 -0
  15. data/data/new/spider.rb.erb +26 -0
  16. data/data/new/webapp/.gitignore +15 -0
  17. data/data/new/webapp/.ruby-version.erb +1 -0
  18. data/data/new/webapp/Dockerfile.erb +11 -0
  19. data/data/new/webapp/Gemfile +6 -0
  20. data/data/new/webapp/app.rb.erb +15 -0
  21. data/data/new/webapp/config.ru +4 -0
  22. data/data/new/webapp/docker-compose.yml.erb +9 -0
  23. data/gemspec.yml +38 -16
  24. data/lib/ronin/web/cli/command.rb +36 -0
  25. data/lib/ronin/web/cli/commands/diff.rb +106 -0
  26. data/lib/ronin/web/cli/commands/html.rb +174 -0
  27. data/lib/ronin/web/cli/commands/irb.rb +56 -0
  28. data/lib/ronin/web/cli/commands/new/nokogiri.rb +85 -0
  29. data/lib/ronin/web/cli/commands/new/server.rb +96 -0
  30. data/lib/ronin/web/cli/commands/new/spider.rb +315 -0
  31. data/lib/ronin/web/cli/commands/new/webapp.rb +123 -0
  32. data/lib/ronin/web/cli/commands/new.rb +64 -0
  33. data/lib/ronin/web/cli/commands/reverse_proxy.rb +215 -0
  34. data/lib/ronin/web/cli/commands/server.rb +155 -0
  35. data/lib/ronin/web/cli/commands/spider.rb +822 -0
  36. data/lib/ronin/web/cli/ruby_shell.rb +50 -0
  37. data/lib/ronin/web/cli.rb +49 -0
  38. data/lib/ronin/web/html.rb +85 -0
  39. data/lib/ronin/web/mechanize.rb +34 -36
  40. data/lib/ronin/web/root.rb +27 -0
  41. data/lib/ronin/web/version.rb +7 -10
  42. data/lib/ronin/web/xml.rb +85 -0
  43. data/lib/ronin/web.rb +372 -13
  44. data/man/ronin-web-diff.1 +41 -0
  45. data/man/ronin-web-diff.1.md +30 -0
  46. data/man/ronin-web-html.1 +89 -0
  47. data/man/ronin-web-html.1.md +66 -0
  48. data/man/ronin-web-irb.1 +31 -0
  49. data/man/ronin-web-irb.1.md +22 -0
  50. data/man/ronin-web-new-nokogiri.1 +41 -0
  51. data/man/ronin-web-new-nokogiri.1.md +30 -0
  52. data/man/ronin-web-new-server.1 +45 -0
  53. data/man/ronin-web-new-server.1.md +33 -0
  54. data/man/ronin-web-new-spider.1 +173 -0
  55. data/man/ronin-web-new-spider.1.md +129 -0
  56. data/man/ronin-web-new-webapp.1 +53 -0
  57. data/man/ronin-web-new-webapp.1.md +39 -0
  58. data/man/ronin-web-new.1 +59 -0
  59. data/man/ronin-web-new.1.md +44 -0
  60. data/man/ronin-web-reverse-proxy.1 +63 -0
  61. data/man/ronin-web-reverse-proxy.1.md +47 -0
  62. data/man/ronin-web-server.1 +59 -0
  63. data/man/ronin-web-server.1.md +43 -0
  64. data/man/ronin-web-spider.1 +225 -0
  65. data/man/ronin-web-spider.1.md +168 -0
  66. data/man/ronin-web.1 +41 -0
  67. data/man/ronin-web.1.md +30 -0
  68. data/ronin-web.gemspec +39 -109
  69. data/spec/cli/ruby_shell_spec.rb +14 -0
  70. data/spec/html_spec.rb +43 -0
  71. data/spec/mechanize_spec.rb +72 -0
  72. data/spec/spec_helper.rb +5 -3
  73. data/spec/web_spec.rb +97 -0
  74. data/spec/xml_spec.rb +42 -0
  75. metadata +236 -224
  76. data/.gemtest +0 -0
  77. data/data/ronin/web/user_agents.yml +0 -247
  78. data/lib/ronin/network/mixins/web.rb +0 -258
  79. data/lib/ronin/web/config.rb +0 -34
  80. data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +0 -47
  81. data/lib/ronin/web/extensions/nokogiri/xml/document.rb +0 -48
  82. data/lib/ronin/web/extensions/nokogiri/xml/element.rb +0 -57
  83. data/lib/ronin/web/extensions/nokogiri/xml/node.rb +0 -86
  84. data/lib/ronin/web/extensions/nokogiri/xml/text.rb +0 -47
  85. data/lib/ronin/web/extensions/nokogiri/xml.rb +0 -27
  86. data/lib/ronin/web/extensions/nokogiri.rb +0 -23
  87. data/lib/ronin/web/extensions.rb +0 -23
  88. data/lib/ronin/web/middleware/base.rb +0 -144
  89. data/lib/ronin/web/middleware/directories.rb +0 -179
  90. data/lib/ronin/web/middleware/files.rb +0 -144
  91. data/lib/ronin/web/middleware/filters/campaign_filter.rb +0 -77
  92. data/lib/ronin/web/middleware/filters/ip_filter.rb +0 -73
  93. data/lib/ronin/web/middleware/filters/path_filter.rb +0 -73
  94. data/lib/ronin/web/middleware/filters/referer_filter.rb +0 -71
  95. data/lib/ronin/web/middleware/filters/user_agent_filter.rb +0 -71
  96. data/lib/ronin/web/middleware/filters/vhost_filter.rb +0 -71
  97. data/lib/ronin/web/middleware/filters.rb +0 -28
  98. data/lib/ronin/web/middleware/helpers.rb +0 -145
  99. data/lib/ronin/web/middleware/proxy.rb +0 -265
  100. data/lib/ronin/web/middleware/proxy_request.rb +0 -262
  101. data/lib/ronin/web/middleware/request.rb +0 -79
  102. data/lib/ronin/web/middleware/response.rb +0 -33
  103. data/lib/ronin/web/middleware/router.rb +0 -167
  104. data/lib/ronin/web/middleware/rule.rb +0 -103
  105. data/lib/ronin/web/middleware.rb +0 -27
  106. data/lib/ronin/web/proxy/app.rb +0 -32
  107. data/lib/ronin/web/proxy/base.rb +0 -46
  108. data/lib/ronin/web/proxy/web.rb +0 -46
  109. data/lib/ronin/web/proxy.rb +0 -25
  110. data/lib/ronin/web/server/app.rb +0 -32
  111. data/lib/ronin/web/server/base.rb +0 -461
  112. data/lib/ronin/web/server/web.rb +0 -66
  113. data/lib/ronin/web/server.rb +0 -25
  114. data/lib/ronin/web/spider.rb +0 -120
  115. data/lib/ronin/web/user_agents.rb +0 -196
  116. data/lib/ronin/web/web.rb +0 -560
  117. data/spec/helpers/output.rb +0 -3
  118. data/spec/web/extensions/nokogiri_spec.rb +0 -38
  119. data/spec/web/helpers/rack_app.rb +0 -24
  120. data/spec/web/helpers/root/test1/index.html +0 -1
  121. data/spec/web/helpers/root/test1/test1.txt +0 -1
  122. data/spec/web/helpers/root/test1.txt +0 -1
  123. data/spec/web/helpers/root/test2/test2.txt +0 -1
  124. data/spec/web/helpers/root/test2.txt +0 -1
  125. data/spec/web/helpers/root/test3/test3.txt +0 -1
  126. data/spec/web/helpers/root/test3.txt +0 -1
  127. data/spec/web/helpers/root.rb +0 -15
  128. data/spec/web/mechanize_spec.rb +0 -62
  129. data/spec/web/middleware/directories_spec.rb +0 -86
  130. data/spec/web/middleware/files_spec.rb +0 -57
  131. data/spec/web/middleware/filters/campaign_filter_spec.rb +0 -30
  132. data/spec/web/middleware/filters/ip_filter_spec.rb +0 -25
  133. data/spec/web/middleware/filters/path_filter_spec.rb +0 -29
  134. data/spec/web/middleware/filters/referer_filter_spec.rb +0 -25
  135. data/spec/web/middleware/filters/user_agent_filter_spec.rb +0 -25
  136. data/spec/web/middleware/filters/vhost_filter_spec.rb +0 -23
  137. data/spec/web/middleware/proxy_spec.rb +0 -67
  138. data/spec/web/middleware/response_spec.rb +0 -20
  139. data/spec/web/middleware/router_spec.rb +0 -65
  140. data/spec/web/middleware/rule_spec.rb +0 -37
  141. data/spec/web/proxy/base_spec.rb +0 -8
  142. data/spec/web/server/base_spec.rb +0 -77
  143. data/spec/web/server/classes/public1/static1.txt +0 -1
  144. data/spec/web/server/classes/public2/static2.txt +0 -1
  145. data/spec/web/server/classes/sub_app.rb +0 -13
  146. data/spec/web/server/classes/test_app.rb +0 -20
  147. data/spec/web/user_agents_spec.rb +0 -56
  148. data/spec/web/web_spec.rb +0 -101
@@ -1,145 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This file is part of Ronin Web.
8
- #
9
- # Ronin is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # Ronin is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU General Public License
20
- # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
21
- #
22
-
23
- require 'ronin/web/middleware/request'
24
- require 'ronin/web/middleware/response'
25
-
26
- require 'rack'
27
-
28
- module Ronin
29
- module Web
30
- module Middleware
31
- #
32
- # A module containing helper methods that can be used in Rack
33
- # Middleware and Rack Apps.
34
- #
35
- module Helpers
36
- include Rack::Utils
37
-
38
- alias h escape_html
39
-
40
- #
41
- # Sanitizes a path received by the middleware.
42
- #
43
- # @param [String] path
44
- # The unsanitized path.
45
- #
46
- # @return [String]
47
- # The unescaped and absolute path.
48
- #
49
- # @since 0.3.0
50
- #
51
- # @api semipublic
52
- #
53
- def sanitize_path(path)
54
- File.expand_path(unescape(path))
55
- end
56
-
57
- #
58
- # Returns the MIME type for a path.
59
- #
60
- # @param [String] path
61
- # The path to determine the MIME type for.
62
- #
63
- # @return [String]
64
- # The MIME type for the path.
65
- #
66
- # @since 0.3.0
67
- #
68
- # @api semipublic
69
- #
70
- def mime_type_for(path)
71
- Rack::Mime.mime_type(File.extname(path))
72
- end
73
-
74
- alias content_type_for mime_type_for
75
-
76
- #
77
- # Creates a new response.
78
- #
79
- # @param [String, Array, IO] body
80
- # The body for the response.
81
- #
82
- # @param [Hash] headers
83
- # Additional headers for the response.
84
- #
85
- # @param [Integer] status
86
- # The HTTP Status Code for the response.
87
- #
88
- # @yield [response]
89
- # If a block is given, it will be passed the new response.
90
- #
91
- # @yieldparam [Response] response
92
- # The new response.
93
- #
94
- # @return [Array]
95
- # The new response.
96
- #
97
- # @example Create a response.
98
- # response ['Hello'], {'Content-Type' => 'text/txt'}, 200
99
- #
100
- # @example Create a response with just a String.
101
- # response 'Hello'
102
- #
103
- # @since 0.3.0
104
- #
105
- # @api semipublic
106
- #
107
- def response(body=[],headers={},status=200)
108
- response = Response.new(body,status,headers)
109
-
110
- yield(response) if block_given?
111
- return response
112
- end
113
-
114
- #
115
- # Creates a new response for a file.
116
- #
117
- # @param [String] path
118
- # The path to the file.
119
- #
120
- # @param [Hash] headers
121
- # Additional headers for the response.
122
- #
123
- # @param [Integer] status
124
- # The HTTP Status Code for the response.
125
- #
126
- # @return [Response]
127
- # The new response object.
128
- #
129
- # @see #response
130
- #
131
- # @since 0.3.0
132
- #
133
- # @api semipublic
134
- #
135
- def response_for(path,headers={},status=200)
136
- response(
137
- File.new(path),
138
- headers.merge('Content-Type' => mime_type_for(path)),
139
- status
140
- )
141
- end
142
- end
143
- end
144
- end
145
- end
@@ -1,265 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This file is part of Ronin Web.
8
- #
9
- # Ronin is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # Ronin is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU General Public License
20
- # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
21
- #
22
-
23
- require 'ronin/web/middleware/base'
24
- require 'ronin/web/middleware/rule'
25
- require 'ronin/web/middleware/proxy_request'
26
-
27
- require 'ronin/network/http'
28
- require 'set'
29
-
30
- module Ronin
31
- module Web
32
- module Middleware
33
- #
34
- # A Rack middleware for proxying requests.
35
- #
36
- # use Ronin::Web::Middleware::Proxy do |proxy|
37
- # proxy.every_request do |request|
38
- # puts request.url
39
- # end
40
- #
41
- # proxy.every_response do |response|
42
- # response.headers.each do |name,value|
43
- # puts "#{name}: #{value}"
44
- # end
45
- #
46
- # puts response.body
47
- # end
48
- # end
49
- #
50
- class Proxy < Base
51
-
52
- # Blacklisted HTTP response Headers.
53
- HEADERS_BLACKLIST = Set[
54
- 'Transfer-Encoding'
55
- ]
56
-
57
- #
58
- # Creates a new {Proxy} middleware.
59
- #
60
- # @param [#call] app
61
- # The application that the proxy middleware sits in front of.
62
- #
63
- # @param [Hash] options
64
- # Additional options.
65
- #
66
- # @option options [String] :campaign
67
- # The name of the campaign who's targetted hosts will be
68
- # filtered by.
69
- #
70
- # @option options [String, Regexp] :vhost
71
- # The Virtual-Host to filter.
72
- #
73
- # @option options [String, IPAddr] :ip
74
- # The IP address or IP range to filter.
75
- #
76
- # @option options [String, Regexp] :referer
77
- # The Referer URL or pattern to filter.
78
- #
79
- # @option options [String, Regexp] :user_agent
80
- # The User-Agent string to filter.
81
- #
82
- # @option options [Proc] :when
83
- # Custom logic to filter requests by.
84
- #
85
- # @yield [proxy]
86
- # If a block is given, it will be passed the new proxy middleware.
87
- #
88
- # @yieldparam [Proxy] proxy
89
- # The new proxy middleware object.
90
- #
91
- # @since 0.3.0
92
- #
93
- # @api public
94
- #
95
- def initialize(app,options={},&block)
96
- intercept(options)
97
-
98
- super(app,options,&block)
99
- end
100
-
101
- #
102
- # Specifies which requests will be intercepted.
103
- #
104
- # @param [Hash] options
105
- # Additional options.
106
- #
107
- # @option options [String] :campaign
108
- # The name of the campaign who's targetted hosts will be
109
- # filtered by.
110
- #
111
- # @option options [String, Regexp] :vhost
112
- # The Virtual-Host to filter.
113
- #
114
- # @option options [String, IPAddr] :ip
115
- # The IP address or IP range to filter.
116
- #
117
- # @option options [String, Regexp] :referer
118
- # The Referer URL or pattern to filter.
119
- #
120
- # @option options [String, Regexp] :user_agent
121
- # The User-Agent string to filter.
122
- #
123
- # @option options [Proc] :when
124
- # Custom logic to filter requests by.
125
- #
126
- # @since 0.3.0
127
- #
128
- # @api public
129
- #
130
- def intercept(options={})
131
- @rule = Rule.new(options)
132
- end
133
-
134
- #
135
- # Uses the given block to intercept incoming requests.
136
- #
137
- # @yield [request]
138
- # The given block will receive every incoming request, before it
139
- # is proxied.
140
- #
141
- # @yieldparam [ProxyRequest] request
142
- # A proxied request.
143
- #
144
- # @return [Proxy]
145
- # The proxy middleware.
146
- #
147
- # @since 0.3.0
148
- #
149
- # @api public
150
- #
151
- def every_request(&block)
152
- @every_request_block = block
153
- return self
154
- end
155
-
156
- #
157
- # Uses the given block to intercept proxied responses.
158
- #
159
- # @yield [response]
160
- # The given block will receive every proxied response.
161
- #
162
- # @yieldparam [Response] response
163
- # A proxied response.
164
- #
165
- # @return [Proxy]
166
- # The proxy middleware.
167
- #
168
- # @since 0.3.0
169
- #
170
- # @api public
171
- #
172
- def every_response(&block)
173
- @every_response_block = block
174
- return self
175
- end
176
-
177
- #
178
- # Receives incoming requests, proxies them, allowing manipulation
179
- # of the requests and their responses.
180
- #
181
- # @param [Hash, Rack::Request] env
182
- # The request.
183
- #
184
- # @return [Array, Response]
185
- # The response.
186
- #
187
- # @since 0.3.0
188
- #
189
- # @api public
190
- #
191
- def call(env)
192
- request = ProxyRequest.new(env)
193
-
194
- if @rule.match?(request)
195
- @every_request_block.call(request) if @every_request_block
196
- else
197
- return super(env)
198
- end
199
-
200
- print_info "Proxying #{request.url} for #{request.address}"
201
- request.headers.each do |name,value|
202
- print_debug " #{name}: #{value}"
203
- end
204
-
205
- response = proxy(request)
206
-
207
- @every_response_block.call(response) if @every_response_block
208
-
209
- print_info "Returning proxied response for #{request.address}"
210
- response.headers.each do |name,value|
211
- print_debug " #{name}: #{value}"
212
- end
213
-
214
- return response
215
- end
216
-
217
- protected
218
-
219
- #
220
- # Proxies a request.
221
- #
222
- # @param [ProxyRequest] request
223
- # The request to send.
224
- #
225
- # @return [Response]
226
- # The response from the request.
227
- #
228
- # @api private
229
- #
230
- def proxy(request)
231
- options = {
232
- :ssl => (request.scheme == 'https'),
233
- :host => request.host,
234
- :port => request.port,
235
- :method => request.request_method,
236
- :path => request.path_info,
237
- :query => request.query_string,
238
- :content_type => request.content_type,
239
- :headers => request.headers
240
- }
241
-
242
- if request.form_data?
243
- options[:form_data] = request.POST
244
- end
245
-
246
- http_response = Net.http_request(options)
247
- http_headers = {}
248
-
249
- http_response.each_capitalized do |name,value|
250
- unless HEADERS_BLACKLIST.include?(name)
251
- http_headers[name] = value
252
- end
253
- end
254
-
255
- return Response.new(
256
- (http_response.body || ''),
257
- http_response.code,
258
- http_headers
259
- )
260
- end
261
-
262
- end
263
- end
264
- end
265
- end
@@ -1,262 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This file is part of Ronin Web.
8
- #
9
- # Ronin is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # Ronin is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU General Public License
20
- # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
21
- #
22
-
23
- require 'ronin/web/middleware/request'
24
-
25
- module Ronin
26
- module Web
27
- module Middleware
28
- class ProxyRequest < Request
29
-
30
- #
31
- # Changes the HTTP Host header of the request.
32
- #
33
- # @param [String] new_host
34
- # The new value of the HTTP Host header.
35
- #
36
- # @return [String]
37
- # The new HTTP Host header.
38
- #
39
- # @since 0.3.0
40
- #
41
- # @api public
42
- #
43
- def host=(new_host)
44
- @env['HTTP_HOST'] = new_host
45
- end
46
-
47
- #
48
- # Changes the port the request is being sent to.
49
- #
50
- # @param [Integer] new_port
51
- # The new port the request will be sent to.
52
- #
53
- # @return [Integer]
54
- # The new port the request will be sent to.
55
- #
56
- # @since 0.3.0
57
- #
58
- # @api public
59
- #
60
- def port=(new_port)
61
- @env['SERVER_PORT'] = new_port
62
- end
63
-
64
- #
65
- # Changes the URI scheme of the request.
66
- #
67
- # @param [String] new_port
68
- # The new URI scheme for the request.
69
- #
70
- # @return [String]
71
- # The new URI scheme of the request.
72
- #
73
- # @since 0.3.0
74
- #
75
- # @api public
76
- #
77
- def scheme=(new_scheme)
78
- @env['rack.url_scheme'] = new_scheme
79
- end
80
-
81
- #
82
- # Causes the request to be proxied over SSL.
83
- #
84
- # @return [ProxyRequest]
85
- # The proxy request.
86
- #
87
- # @since 0.3.0
88
- #
89
- # @api public
90
- #
91
- def ssl!
92
- self.port = 443
93
- self.scheme = 'https'
94
-
95
- return self
96
- end
97
-
98
- #
99
- # Changes the HTTP Request Method of the request.
100
- #
101
- # @param [String] new_method
102
- # The new HTTP Request Method.
103
- #
104
- # @return [String]
105
- # The new HTTP Request Method.
106
- #
107
- # @since 0.3.0
108
- #
109
- # @api public
110
- #
111
- def request_method=(new_method)
112
- @env['REQUEST_METHOD'] = new_method
113
- end
114
-
115
- alias path= path_info=
116
-
117
- #
118
- # Changes the HTTP Query String of the request.
119
- #
120
- # @param [String] new_query
121
- # The new HTTP Query String for the request.
122
- #
123
- # @return [String]
124
- # The new HTTP Query String of the request.
125
- #
126
- # @since 0.3.0
127
- #
128
- # @api public
129
- #
130
- def query_string=(new_query)
131
- @env['QUERY_STRING'] = new_query
132
- end
133
-
134
- #
135
- # Determines if the request is an XML-HTTP Request.
136
- #
137
- # @return [Boolean]
138
- # Specifies whether the request is XML-HTTP.
139
- #
140
- # @since 0.3.0
141
- #
142
- # @api public
143
- #
144
- def xhr?
145
- @env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
146
- end
147
-
148
- #
149
- # Specifies that the request is a XML HTTP Request.
150
- #
151
- # @yield [request]
152
- # If a block is given, it will be passed the request
153
- # for further modification.
154
- #
155
- # @yieldparam [ProxyRequest] request
156
- # The proxy request.
157
- #
158
- # @return [ProxyRequest]
159
- # The request.
160
- #
161
- # @since 0.3.0
162
- #
163
- # @api public
164
- #
165
- def xhr!
166
- @env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
167
-
168
- yield self if block_given?
169
- return self
170
- end
171
-
172
- #
173
- # Changes the HTTP Content-Type header of the request.
174
- #
175
- # @param [String] new_content_type
176
- # The new HTTP Content-Type for the request.
177
- #
178
- # @return [String]
179
- # The new HTTP Content-Type of the request.
180
- #
181
- # @since 0.3.0
182
- #
183
- # @api public
184
- #
185
- def content_type=(new_content_type)
186
- @env['CONTENT_TYPE'] = new_content_type
187
- end
188
-
189
- #
190
- # Changes the HTTP Accept-Encoding header of the request.
191
- #
192
- # @param [String] new_encoding
193
- # The new HTTP Accept-Encoding for the request.
194
- #
195
- # @return [String]
196
- # The new HTTP Accept-Encoding of the request.
197
- #
198
- # @since 0.3.0
199
- #
200
- # @api public
201
- #
202
- def accept_encoding=(new_encoding)
203
- @env['HTTP_ACCEPT_ENCODING'] = new_encoding
204
- end
205
-
206
- #
207
- # Sets the HTTP User-Agent header of the request.
208
- #
209
- # @param [String] new_user_agent
210
- # The new User-Agent header to use.
211
- #
212
- # @return [String]
213
- # The new User-Agent header.
214
- #
215
- # @since 0.3.0
216
- #
217
- # @api public
218
- #
219
- def user_agent=(new_user_agent)
220
- @env['HTTP_USER_AGENT'] = new_user_agent
221
- end
222
-
223
- #
224
- # Changes the HTTP Referer header of the request.
225
- #
226
- # @param [String] new_referer
227
- # The new HTTP Referer for the request.
228
- #
229
- # @return [String]
230
- # The new HTTP Referer of the request.
231
- #
232
- # @since 0.3.0
233
- #
234
- # @api public
235
- #
236
- def referer=(new_referer)
237
- @env['HTTP_REFERER'] = new_referer
238
- end
239
-
240
- alias referrer= referer=
241
-
242
- #
243
- # Changes the body of the request.
244
- #
245
- # @param [String] new_body
246
- # The new body for the request.
247
- #
248
- # @return [String]
249
- # The new body of the request.
250
- #
251
- # @since 0.3.0
252
- #
253
- # @api public
254
- #
255
- def body=(new_body)
256
- @env['rack.input'] = new_body
257
- end
258
-
259
- end
260
- end
261
- end
262
- end