Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: webrick.rb
##
[0] Fix | Delete
# = WEB server toolkit.
[1] Fix | Delete
#
[2] Fix | Delete
# WEBrick is an HTTP server toolkit that can be configured as an HTTPS server,
[3] Fix | Delete
# a proxy server, and a virtual-host server. WEBrick features complete
[4] Fix | Delete
# logging of both server operations and HTTP access. WEBrick supports both
[5] Fix | Delete
# basic and digest authentication in addition to algorithms not in RFC 2617.
[6] Fix | Delete
#
[7] Fix | Delete
# A WEBrick server can be composed of multiple WEBrick servers or servlets to
[8] Fix | Delete
# provide differing behavior on a per-host or per-path basis. WEBrick
[9] Fix | Delete
# includes servlets for handling CGI scripts, ERb pages, Ruby blocks and
[10] Fix | Delete
# directory listings.
[11] Fix | Delete
#
[12] Fix | Delete
# WEBrick also includes tools for daemonizing a process and starting a process
[13] Fix | Delete
# at a higher privilege level and dropping permissions.
[14] Fix | Delete
#
[15] Fix | Delete
# == Starting an HTTP server
[16] Fix | Delete
#
[17] Fix | Delete
# To create a new WEBrick::HTTPServer that will listen to connections on port
[18] Fix | Delete
# 8000 and serve documents from the current user's public_html folder:
[19] Fix | Delete
#
[20] Fix | Delete
# require 'webrick'
[21] Fix | Delete
#
[22] Fix | Delete
# root = File.expand_path '~/public_html'
[23] Fix | Delete
# server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
[24] Fix | Delete
#
[25] Fix | Delete
# To run the server you will need to provide a suitable shutdown hook as
[26] Fix | Delete
# starting the server blocks the current thread:
[27] Fix | Delete
#
[28] Fix | Delete
# trap 'INT' do server.shutdown end
[29] Fix | Delete
#
[30] Fix | Delete
# server.start
[31] Fix | Delete
#
[32] Fix | Delete
# == Custom Behavior
[33] Fix | Delete
#
[34] Fix | Delete
# The easiest way to have a server perform custom operations is through
[35] Fix | Delete
# WEBrick::HTTPServer#mount_proc. The block given will be called with a
[36] Fix | Delete
# WEBrick::HTTPRequest with request info and a WEBrick::HTTPResponse which
[37] Fix | Delete
# must be filled in appropriately:
[38] Fix | Delete
#
[39] Fix | Delete
# server.mount_proc '/' do |req, res|
[40] Fix | Delete
# res.body = 'Hello, world!'
[41] Fix | Delete
# end
[42] Fix | Delete
#
[43] Fix | Delete
# Remember that +server.mount_proc+ must precede +server.start+.
[44] Fix | Delete
#
[45] Fix | Delete
# == Servlets
[46] Fix | Delete
#
[47] Fix | Delete
# Advanced custom behavior can be obtained through mounting a subclass of
[48] Fix | Delete
# WEBrick::HTTPServlet::AbstractServlet. Servlets provide more modularity
[49] Fix | Delete
# when writing an HTTP server than mount_proc allows. Here is a simple
[50] Fix | Delete
# servlet:
[51] Fix | Delete
#
[52] Fix | Delete
# class Simple < WEBrick::HTTPServlet::AbstractServlet
[53] Fix | Delete
# def do_GET request, response
[54] Fix | Delete
# status, content_type, body = do_stuff_with request
[55] Fix | Delete
#
[56] Fix | Delete
# response.status = 200
[57] Fix | Delete
# response['Content-Type'] = 'text/plain'
[58] Fix | Delete
# response.body = 'Hello, World!'
[59] Fix | Delete
# end
[60] Fix | Delete
# end
[61] Fix | Delete
#
[62] Fix | Delete
# To initialize the servlet you mount it on the server:
[63] Fix | Delete
#
[64] Fix | Delete
# server.mount '/simple', Simple
[65] Fix | Delete
#
[66] Fix | Delete
# See WEBrick::HTTPServlet::AbstractServlet for more details.
[67] Fix | Delete
#
[68] Fix | Delete
# == Virtual Hosts
[69] Fix | Delete
#
[70] Fix | Delete
# A server can act as a virtual host for multiple host names. After creating
[71] Fix | Delete
# the listening host, additional hosts that do not listen can be created and
[72] Fix | Delete
# attached as virtual hosts:
[73] Fix | Delete
#
[74] Fix | Delete
# server = WEBrick::HTTPServer.new # ...
[75] Fix | Delete
#
[76] Fix | Delete
# vhost = WEBrick::HTTPServer.new :ServerName => 'vhost.example',
[77] Fix | Delete
# :DoNotListen => true, # ...
[78] Fix | Delete
# vhost.mount '/', ...
[79] Fix | Delete
#
[80] Fix | Delete
# server.virtual_host vhost
[81] Fix | Delete
#
[82] Fix | Delete
# If no +:DocumentRoot+ is provided and no servlets or procs are mounted on the
[83] Fix | Delete
# main server it will return 404 for all URLs.
[84] Fix | Delete
#
[85] Fix | Delete
# == HTTPS
[86] Fix | Delete
#
[87] Fix | Delete
# To create an HTTPS server you only need to enable SSL and provide an SSL
[88] Fix | Delete
# certificate name:
[89] Fix | Delete
#
[90] Fix | Delete
# require 'webrick'
[91] Fix | Delete
# require 'webrick/https'
[92] Fix | Delete
#
[93] Fix | Delete
# cert_name = [
[94] Fix | Delete
# %w[CN localhost],
[95] Fix | Delete
# ]
[96] Fix | Delete
#
[97] Fix | Delete
# server = WEBrick::HTTPServer.new(:Port => 8000,
[98] Fix | Delete
# :SSLEnable => true,
[99] Fix | Delete
# :SSLCertName => cert_name)
[100] Fix | Delete
#
[101] Fix | Delete
# This will start the server with a self-generated self-signed certificate.
[102] Fix | Delete
# The certificate will be changed every time the server is restarted.
[103] Fix | Delete
#
[104] Fix | Delete
# To create a server with a pre-determined key and certificate you can provide
[105] Fix | Delete
# them:
[106] Fix | Delete
#
[107] Fix | Delete
# require 'webrick'
[108] Fix | Delete
# require 'webrick/https'
[109] Fix | Delete
# require 'openssl'
[110] Fix | Delete
#
[111] Fix | Delete
# cert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem'
[112] Fix | Delete
# pkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem'
[113] Fix | Delete
#
[114] Fix | Delete
# server = WEBrick::HTTPServer.new(:Port => 8000,
[115] Fix | Delete
# :SSLEnable => true,
[116] Fix | Delete
# :SSLCertificate => cert,
[117] Fix | Delete
# :SSLPrivateKey => pkey)
[118] Fix | Delete
#
[119] Fix | Delete
# == Proxy Server
[120] Fix | Delete
#
[121] Fix | Delete
# WEBrick can act as a proxy server:
[122] Fix | Delete
#
[123] Fix | Delete
# require 'webrick'
[124] Fix | Delete
# require 'webrick/httpproxy'
[125] Fix | Delete
#
[126] Fix | Delete
# proxy = WEBrick::HTTPProxyServer.new :Port => 8000
[127] Fix | Delete
#
[128] Fix | Delete
# trap 'INT' do proxy.shutdown end
[129] Fix | Delete
#
[130] Fix | Delete
# See WEBrick::HTTPProxy for further details including modifying proxied
[131] Fix | Delete
# responses.
[132] Fix | Delete
#
[133] Fix | Delete
# == Basic and Digest authentication
[134] Fix | Delete
#
[135] Fix | Delete
# WEBrick provides both Basic and Digest authentication for regular and proxy
[136] Fix | Delete
# servers. See WEBrick::HTTPAuth, WEBrick::HTTPAuth::BasicAuth and
[137] Fix | Delete
# WEBrick::HTTPAuth::DigestAuth.
[138] Fix | Delete
#
[139] Fix | Delete
# == WEBrick as a Production Web Server
[140] Fix | Delete
#
[141] Fix | Delete
# WEBrick can be run as a production server for small loads.
[142] Fix | Delete
#
[143] Fix | Delete
# === Daemonizing
[144] Fix | Delete
#
[145] Fix | Delete
# To start a WEBrick server as a daemon simple run WEBrick::Daemon.start
[146] Fix | Delete
# before starting the server.
[147] Fix | Delete
#
[148] Fix | Delete
# === Dropping Permissions
[149] Fix | Delete
#
[150] Fix | Delete
# WEBrick can be started as one user to gain permission to bind to port 80 or
[151] Fix | Delete
# 443 for serving HTTP or HTTPS traffic then can drop these permissions for
[152] Fix | Delete
# regular operation. To listen on all interfaces for HTTP traffic:
[153] Fix | Delete
#
[154] Fix | Delete
# sockets = WEBrick::Utils.create_listeners nil, 80
[155] Fix | Delete
#
[156] Fix | Delete
# Then drop privileges:
[157] Fix | Delete
#
[158] Fix | Delete
# WEBrick::Utils.su 'www'
[159] Fix | Delete
#
[160] Fix | Delete
# Then create a server that does not listen by default:
[161] Fix | Delete
#
[162] Fix | Delete
# server = WEBrick::HTTPServer.new :DoNotListen => true, # ...
[163] Fix | Delete
#
[164] Fix | Delete
# Then overwrite the listening sockets with the port 80 sockets:
[165] Fix | Delete
#
[166] Fix | Delete
# server.listeners.replace sockets
[167] Fix | Delete
#
[168] Fix | Delete
# === Logging
[169] Fix | Delete
#
[170] Fix | Delete
# WEBrick can separately log server operations and end-user access. For
[171] Fix | Delete
# server operations:
[172] Fix | Delete
#
[173] Fix | Delete
# log_file = File.open '/var/log/webrick.log', 'a+'
[174] Fix | Delete
# log = WEBrick::Log.new log_file
[175] Fix | Delete
#
[176] Fix | Delete
# For user access logging:
[177] Fix | Delete
#
[178] Fix | Delete
# access_log = [
[179] Fix | Delete
# [log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
[180] Fix | Delete
# ]
[181] Fix | Delete
#
[182] Fix | Delete
# server = WEBrick::HTTPServer.new :Logger => log, :AccessLog => access_log
[183] Fix | Delete
#
[184] Fix | Delete
# See WEBrick::AccessLog for further log formats.
[185] Fix | Delete
#
[186] Fix | Delete
# === Log Rotation
[187] Fix | Delete
#
[188] Fix | Delete
# To rotate logs in WEBrick on a HUP signal (like syslogd can send), open the
[189] Fix | Delete
# log file in 'a+' mode (as above) and trap 'HUP' to reopen the log file:
[190] Fix | Delete
#
[191] Fix | Delete
# trap 'HUP' do log_file.reopen '/path/to/webrick.log', 'a+'
[192] Fix | Delete
#
[193] Fix | Delete
# == Copyright
[194] Fix | Delete
#
[195] Fix | Delete
# Author: IPR -- Internet Programming with Ruby -- writers
[196] Fix | Delete
#
[197] Fix | Delete
# Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
[198] Fix | Delete
# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
[199] Fix | Delete
# reserved.
[200] Fix | Delete
#--
[201] Fix | Delete
# $IPR: webrick.rb,v 1.12 2002/10/01 17:16:31 gotoyuzo Exp $
[202] Fix | Delete
[203] Fix | Delete
module WEBrick
[204] Fix | Delete
end
[205] Fix | Delete
[206] Fix | Delete
require 'webrick/compat.rb'
[207] Fix | Delete
[208] Fix | Delete
require 'webrick/version.rb'
[209] Fix | Delete
require 'webrick/config.rb'
[210] Fix | Delete
require 'webrick/log.rb'
[211] Fix | Delete
require 'webrick/server.rb'
[212] Fix | Delete
require 'webrick/utils.rb'
[213] Fix | Delete
require 'webrick/accesslog'
[214] Fix | Delete
[215] Fix | Delete
require 'webrick/htmlutils.rb'
[216] Fix | Delete
require 'webrick/httputils.rb'
[217] Fix | Delete
require 'webrick/cookie.rb'
[218] Fix | Delete
require 'webrick/httpversion.rb'
[219] Fix | Delete
require 'webrick/httpstatus.rb'
[220] Fix | Delete
require 'webrick/httprequest.rb'
[221] Fix | Delete
require 'webrick/httpresponse.rb'
[222] Fix | Delete
require 'webrick/httpserver.rb'
[223] Fix | Delete
require 'webrick/httpservlet.rb'
[224] Fix | Delete
require 'webrick/httpauth.rb'
[225] Fix | Delete
[226] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function