proxy_pass: document as a public API
[yahns.git] / lib / yahns.rb
blob4cf911e6a32151203d88966f6af01059706c5867
1 # Copyright (C) 2013-2019 all contributors <yahns-public@yhbt.net>
2 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
3 # frozen_string_literal: true
4 $stdout.sync = $stderr.sync = true
6 require 'unicorn' # pulls in raindrops, kgio, fcntl, etc, stringio, and logger
7 require 'sleepy_penguin'
8 require 'io/wait'
10 # kill off some unicorn internals we don't need
11 # we'll probably just make kcar into a server parser so we don't depend
12 # on unicorn at all
13 [ :ClientShutdown, :Const, :SocketHelper, :StreamInput, :TeeInput,
14   :SSLConfigurator, :Configurator, :TmpIO, :Util, :Worker, :SSLServer,
15   :HttpServer ].each do |sym|
16     Unicorn.__send__(:remove_const, sym) if Unicorn.const_defined?(sym)
17 end
19 # yahns exposes little user-visible API outside of the config file.
20 # See https://yhbt.net/yahns/yahns_config.txt
21 # for the config documentation (or yahns_config(5) manpage)
22 # and https://yhbt.net/yahns.git/about/ for the homepage.
24 # Yahns::ProxyPass is currently the only public API.
26 # Documented APIs and options are supported forever,
27 # internals are subject to change.
28 module Yahns
29   # :stopdoc:
30   # We populate this at startup so we can figure out how to reexecute
31   # and upgrade the currently running instance of yahns
32   # Unlike unicorn, this Hash is NOT a stable/public interface.
33   #
34   # * 0 - the path to the yahns executable
35   # * :argv - a deep copy of the ARGV array the executable originally saw
36   # * :cwd - the working directory of the application, this is where
37   # you originally started yahns.
38   #
39   # To change your yahns executable to a different path without downtime,
40   # you can set the following in your yahns config file, HUP and then
41   # continue with the traditional USR2 + QUIT upgrade steps:
42   #
43   #   Yahns::START[0] = "/home/bofh/2.0.0/bin/yahns"
44   START = {
45     :argv => ARGV.map(&:dup),
46     0 => $0.dup,
47   }
49   # We favor ENV['PWD'] since it is (usually) symlink aware for Capistrano
50   # and like systems
51   START[:cwd] = begin
52     a = File.stat(pwd = ENV['PWD'])
53     b = File.stat(Dir.pwd)
54     a.ino == b.ino && a.dev == b.dev ? pwd : Dir.pwd
55   rescue
56     Dir.pwd
57   end
59   # Raised inside TeeInput when a client closes the socket inside the
60   # application dispatch.  This is always raised with an empty backtrace
61   # since there is nothing in the application stack that is responsible
62   # for client shutdowns/disconnects.
63   ClientShutdown = Class.new(EOFError) # :nodoc:
65   ClientTimeout = Class.new(RuntimeError) # :nodoc:
67   # try to use the monotonic clock in Ruby >= 2.1, it is immune to clock
68   # offset adjustments and generates less garbage (Float vs Time object)
69   begin
70     def self.now # :nodoc:
71       Process.clock_gettime(Process::CLOCK_MONOTONIC) # :nodoc:
72     end
73   rescue NameError, NoMethodError
74     def self.now # :nodoc:
75       Time.now.to_f # Ruby <= 2.0
76     end
77   end
79   # :startdoc:
80 end
82 # FIXME: require lazily
83 require_relative 'yahns/log'
84 require_relative 'yahns/queue'
85 require_relative 'yahns/stream_input'
86 require_relative 'yahns/tee_input'
87 require_relative 'yahns/queue_egg'
88 require_relative 'yahns/http_response'
89 require_relative 'yahns/http_client'
90 require_relative 'yahns/http_context'
91 require_relative 'yahns/queue'
92 require_relative 'yahns/config'
93 require_relative 'yahns/tmpio'
94 require_relative 'yahns/worker'
95 require_relative 'yahns/sigevent'
96 require_relative 'yahns/socket_helper'
97 require_relative 'yahns/server'
98 require_relative 'yahns/fdmap'
99 require_relative 'yahns/acceptor'
100 require_relative 'yahns/wbuf'
101 require_relative 'yahns/version'