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