Class: WEBrick::CGI::Socket

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/webrick/cgi.rb

Overview

Provides HTTP socket emulation from the CGI environment

Instance Method Summary collapse

Instance Method Details

#<<(data) ⇒ Object



264
265
266
# File 'lib/webrick/cgi.rb', line 264

def <<(data)
  @out_port << data
end

#addrObject



244
245
246
# File 'lib/webrick/cgi.rb', line 244

def addr
  [nil, @server_port, @server_name, @server_addr]
end

#certObject



272
273
274
275
276
277
# File 'lib/webrick/cgi.rb', line 272

def cert
  return nil unless defined?(OpenSSL)
  if pem = @env["SSL_SERVER_CERT"]
    OpenSSL::X509::Certificate.new(pem) unless pem.empty?
  end
end

#cipherObject



301
302
303
304
305
306
307
308
309
310
# File 'lib/webrick/cgi.rb', line 301

def cipher
  return nil unless defined?(OpenSSL)
  if cipher = @env["SSL_CIPHER"]
    ret = [ cipher ]
    ret << @env["SSL_PROTOCOL"]
    ret << @env["SSL_CIPHER_USEKEYSIZE"]
    ret << @env["SSL_CIPHER_ALGKEYSIZE"]
    ret
  end
end

#eachObject



256
257
258
# File 'lib/webrick/cgi.rb', line 256

def each
  input.each{|line| yield(line) }
end

#eof?Boolean

Returns:

  • (Boolean)


260
261
262
# File 'lib/webrick/cgi.rb', line 260

def eof?
  input.eof?
end

#gets(eol = LF, size = nil) ⇒ Object



248
249
250
# File 'lib/webrick/cgi.rb', line 248

def gets(eol=LF, size=nil)
  input.gets(eol, size)
end

#peer_certObject



279
280
281
282
283
284
# File 'lib/webrick/cgi.rb', line 279

def peer_cert
  return nil unless defined?(OpenSSL)
  if pem = @env["SSL_CLIENT_CERT"]
    OpenSSL::X509::Certificate.new(pem) unless pem.empty?
  end
end

#peer_cert_chainObject



286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/webrick/cgi.rb', line 286

def peer_cert_chain
  return nil unless defined?(OpenSSL)
  if @env["SSL_CLIENT_CERT_CHAIN_0"]
    keys = @env.keys
    certs = keys.sort.collect{|k|
      if /^SSL_CLIENT_CERT_CHAIN_\d+$/ =~ k
        if pem = @env[k]
          OpenSSL::X509::Certificate.new(pem) unless pem.empty?
        end
      end
    }
    certs.compact
  end
end

#peeraddrObject



240
241
242
# File 'lib/webrick/cgi.rb', line 240

def peeraddr
  [nil, @remote_port, @remote_host, @remote_addr]
end

#read(size = nil) ⇒ Object



252
253
254
# File 'lib/webrick/cgi.rb', line 252

def read(size=nil)
  input.read(size)
end

#write(data) ⇒ Object



268
269
270
# File 'lib/webrick/cgi.rb', line 268

def write(data)
  @out_port.write(data)
end