Project

General

Profile

Feature #2574 ยป merge_https.patch

naruse (Yui NARUSE), 01/08/2010 09:40 AM

View differences:

lib/net/http.rb
26 26
#++
27 27

  
28 28
require 'net/protocol'
29
autoload :OpenSSL, 'openssl'
29 30
require 'uri'
30 31

  
31 32
module Net   #:nodoc:
......
544 545

  
545 546
    # returns true if use SSL/TLS with HTTP.
546 547
    def use_ssl?
547
      false   # redefined in net/https
548
      @use_ssl
549
    end
550

  
551
    # Turn on/off SSL.
552
    # This flag must be set before starting session.
553
    # If you change use_ssl value after session started,
554
    # a Net::HTTP object raises IOError.
555
    def use_ssl=(flag)
556
      flag = (flag ? true : false)
557
      if started? and @use_ssl != flag
558
        raise IOError, "use_ssl value changed, but session already started"
559
      end
560
      @use_ssl = flag
561
    end
562

  
563
    SSL_ATTRIBUTES = %w(
564
      ssl_version key cert ca_file ca_path cert_store ciphers
565
      verify_mode verify_callback verify_depth ssl_timeout
566
    )
567
    attr_accessor(*SSL_ATTRIBUTES)
568

  
569
    # return the X.509 certificates the server presented.
570
    def peer_cert
571
      if not use_ssl? or not @socket
572
        return nil
573
      end
574
      @socket.io.peer_cert
548 575
    end
549 576

  
550 577
    # Opens TCP connection and HTTP session.
lib/net/https.rb
1 1
=begin
2 2

  
3
= $RCSfile$ -- SSL/TLS enhancement for Net::HTTP.
3
= net/https -- SSL/TLS enhancement for Net::HTTP.
4 4

  
5 5
== Info
6 6
  'OpenSSL for Ruby 2' project
......
11 11
  This program is licenced under the same licence as Ruby.
12 12
  (See the file 'LICENCE'.)
13 13

  
14
== Requirements
15
  This program requires Net 1.2.0 or higher version.
16
  You can get it from RAA or Ruby's CVS repository.
17

  
18
== Version
19
  $Id$
20

  
21
  2001-11-06: Contiributed to Ruby/OpenSSL project.
22
  2004-03-06: Some code is merged in to net/http.
23

  
24 14
== Example
25 15

  
26 16
Here is a simple HTTP client:
......
100 90

  
101 91
require 'net/http'
102 92
require 'openssl'
103

  
104
module Net
105
  class HTTP
106
    remove_method :use_ssl?
107
    def use_ssl?
108
      @use_ssl
109
    end
110

  
111
    # Turn on/off SSL.
112
    # This flag must be set before starting session.
113
    # If you change use_ssl value after session started,
114
    # a Net::HTTP object raises IOError.
115
    def use_ssl=(flag)
116
      flag = (flag ? true : false)
117
      if started? and @use_ssl != flag
118
        raise IOError, "use_ssl value changed, but session already started"
119
      end
120
      @use_ssl = flag
121
    end
122

  
123
    SSL_ATTRIBUTES = %w(
124
      ssl_version key cert ca_file ca_path cert_store ciphers
125
      verify_mode verify_callback verify_depth ssl_timeout
126
    )
127
    attr_accessor(*SSL_ATTRIBUTES)
128

  
129
    def peer_cert
130
      if not use_ssl? or not @socket
131
        return nil
132
      end
133
      @socket.io.peer_cert
134
    end
135
  end
136
end