Class: Net::DAV::CurlHandler

Inherits:
NetHttpHandler show all
Defined in:
lib/net/dav.rb

Constant Summary

Constants inherited from NetHttpHandler

NetHttpHandler::CNONCE

Instance Attribute Summary

Attributes inherited from NetHttpHandler

#disable_basic_auth, #last_status, #pass, #user

Instance Method Summary collapse

Methods inherited from NetHttpHandler

#clone_req, #digest_auth, #handle_request, #initialize, #open_timeout, #open_timeout=, #read_timeout, #read_timeout=, #request, #request_sending_body, #request_sending_stream, #start

Constructor Details

This class inherits a constructor from Net::DAV::NetHttpHandler

Instance Method Details

#ca_file(ca_file) ⇒ Object



350
351
352
353
# File 'lib/net/dav.rb', line 350

def ca_file(ca_file)
  # path of a cacert bundle for this instance. This file will be used to validate SSL certificates.
  @curl.cacert = ca_file
end

#cert_file(cert_file) ⇒ Object



338
339
340
341
# File 'lib/net/dav.rb', line 338

def cert_file(cert_file)
  # expects a cert file
  @curl.cert = cert_file
end

#cert_key(cert_file, cert_file_password) ⇒ Object



343
344
345
346
347
348
# File 'lib/net/dav.rb', line 343

def cert_key(cert_file, cert_file_password)
  if cert_file_password then
    @curl.certpassword = cert_file_password
  end
  @curl.key = cert_key
end

#make_curlObject



294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/net/dav.rb', line 294

def make_curl
  unless @curl
    @curl = Curl::Easy.new
    @curl.timeout = @http.read_timeout
    @curl.follow_location = true
    @curl.max_redirects = MAX_REDIRECTS
    if disable_basic_auth
      @curl.http_auth_types = Curl::CURLAUTH_DIGEST
    end
  end
  @curl
end

#request_returning_body(verb, path, headers) ⇒ Object



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/net/dav.rb', line 307

def request_returning_body(verb, path, headers)
  raise "unkown returning_body verb #{verb}" unless verb == :get
  url = @uri.merge(path)
  curl = make_curl
  curl.url = url.to_s
  headers.each_pair { |key, value| curl.headers[key] = value } if headers
  if (@user)
    curl.userpwd = "#{@user}:#{@pass}"
  else
    curl.userpwd = nil
  end
  res = nil
  if block_given?
    curl.on_body do |frag|
      yield frag
      frag.length
    end
  end
  curl.perform

  @last_status = curl.response_code

  unless curl.response_code >= 200 && curl.response_code < 300
    header_block = curl.header_str.split(/\r?\n\r?\n/)[-1]
    msg = header_block.split(/\r?\n/)[0]
    msg.gsub!(/^HTTP\/\d+.\d+ /, '')
    raise Net::HTTPError.new(msg, nil)
  end
  curl.body_str
end

#verify_callback=(callback) ⇒ Object



281
282
283
284
285
# File 'lib/net/dav.rb', line 281

def verify_callback=(callback)
  super
  curl = make_curl
  $stderr.puts "verify_callback not implemented in Curl::Easy"
end

#verify_server=(value) ⇒ Object



287
288
289
290
291
292
# File 'lib/net/dav.rb', line 287

def verify_server=(value)
  super
  curl = make_curl
  curl.ssl_verify_peer = value
  curl.ssl_verify_host = value
end