about summary refs log tree commit homepage
path: root/lib/yahns/http_context.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yahns/http_context.rb')
-rw-r--r--lib/yahns/http_context.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/yahns/http_context.rb b/lib/yahns/http_context.rb
new file mode 100644
index 0000000..1af41df
--- /dev/null
+++ b/lib/yahns/http_context.rb
@@ -0,0 +1,66 @@
+# -*- encoding: binary -*-
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require 'yahns/tiny_input'
+
+# subclasses of Yahns::HttpClient will class extend this
+
+module Yahns::HttpContext # :nodoc:
+  attr_accessor :check_client_connection
+  attr_accessor :client_body_buffer_size
+  attr_accessor :client_header_buffer_size
+  attr_accessor :client_max_body_size
+  attr_accessor :client_max_header_size
+  attr_accessor :input_buffering  # :lazy, true, false
+  attr_accessor :output_buffering # true, false
+  attr_accessor :persistent_connections # true or false only
+  attr_accessor :client_timeout
+  attr_accessor :qegg
+  attr_reader :app
+  attr_reader :app_defaults
+
+  def http_ctx_init(yahns_rack)
+    @yahns_rack = yahns_rack
+    @app_defaults = yahns_rack.app_defaults
+    @check_client_connection = false
+    @client_body_buffer_size = 112 * 1024
+    @client_header_buffer_size = 4000
+    @client_max_body_size = 1024 * 1024
+    @input_buffering = true
+    @output_buffering = true
+    @persistent_connections = true
+    @client_timeout = 15
+    @qegg = nil
+  end
+
+  # call this after forking
+  def after_fork_init
+    @app = @yahns_rack.app_after_fork
+  end
+
+  # call this immediately after successful accept()/accept4()
+  def logger=(l) # cold
+    @logger = @app_defaults["rack.logger"] = l
+  end
+
+  def logger
+    @app_defaults["rack.logger"]
+  end
+
+  def mkinput(client, hs)
+    (@input_buffering ? Yahns::TeeInput : Yahns::StreamInput).new(client, hs)
+  end
+
+  def errors=(dest)
+    @app_defaults["rack.errors"] = dest
+  end
+
+  def errors
+    @app_defaults["rack.errors"]
+  end
+
+  def tmpio_for(len)
+    len && len <= @client_body_buffer_size ?
+      Yahns::TinyInput.new("") : Yahns::TmpIO.new
+  end
+end