Method: SimpleHttp#initialize

Defined in:
lib/ramaze/spec/helper/simple_http.rb

#initialize(uri) ⇒ SimpleHttp

SimpleHttp can either be used directly through the get and post class methods or be instantiated, in case you need to to add custom behaviour to the requests.

Example: http = SimpleHttp.new(URI.parse(“www.example.com”)) http = SimpleHttp.new “www.example.com” http = SimpleHttp.new “usr:[email protected]:1234

Parameters:

  • may

    be a URI or a String.



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/ramaze/spec/helper/simple_http.rb', line 169

def initialize uri
	set_proxy ENV['http_proxy'] if ENV['http_proxy']

	if uri.class == String

		unless uri =~ /^https?:\/\//
			uri = "http://#{uri}"
		end

		uri = URI.parse uri

	end
	@uri = uri
	if !@uri.path || "" == @uri.path.strip
		@uri.path="/"
	end


	@request_headers={}
	@response_headers={}
	@response_handlers=RESPONSE_HANDLERS.clone
	@follow_num_redirects=3

	if @uri.user
		basic_authentication @uri.user, @uri.password
	end

end