Module: Yahns::HttpContext

Defined in:
lib/yahns/http_context.rb

Overview

subclasses of Yahns::HttpClient will class extend this

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



18
19
20
# File 'lib/yahns/http_context.rb', line 18

def app
  @app
end

#app_defaultsObject (readonly)

Returns the value of attribute app_defaults.



19
20
21
# File 'lib/yahns/http_context.rb', line 19

def app_defaults
  @app_defaults
end

#check_client_connectionObject

:nodoc:



8
9
10
# File 'lib/yahns/http_context.rb', line 8

def check_client_connection
  @check_client_connection
end

#client_body_buffer_sizeObject

Returns the value of attribute client_body_buffer_size.



9
10
11
# File 'lib/yahns/http_context.rb', line 9

def client_body_buffer_size
  @client_body_buffer_size
end

#client_header_buffer_sizeObject

Returns the value of attribute client_header_buffer_size.



10
11
12
# File 'lib/yahns/http_context.rb', line 10

def client_header_buffer_size
  @client_header_buffer_size
end

#client_max_body_sizeObject

Returns the value of attribute client_max_body_size.



11
12
13
# File 'lib/yahns/http_context.rb', line 11

def client_max_body_size
  @client_max_body_size
end

#client_timeoutObject

Returns the value of attribute client_timeout.



15
16
17
# File 'lib/yahns/http_context.rb', line 15

def client_timeout
  @client_timeout
end

#input_buffer_tmpdirObject



91
92
93
# File 'lib/yahns/http_context.rb', line 91

def input_buffer_tmpdir
  @input_buffer_tmpdir || Dir.tmpdir
end

#input_bufferingObject

:lazy, true, false



12
13
14
# File 'lib/yahns/http_context.rb', line 12

def input_buffering
  @input_buffering
end

#output_buffer_tmpdirObject



95
96
97
# File 'lib/yahns/http_context.rb', line 95

def output_buffer_tmpdir
  @output_buffer_tmpdir || Dir.tmpdir
end

#output_bufferingObject

true, false



13
14
15
# File 'lib/yahns/http_context.rb', line 13

def output_buffering
  @output_buffering
end

#persistent_connectionsObject

true or false only



14
15
16
# File 'lib/yahns/http_context.rb', line 14

def persistent_connections
  @persistent_connections
end

#qeggObject

Returns the value of attribute qegg.



16
17
18
# File 'lib/yahns/http_context.rb', line 16

def qegg
  @qegg
end

#queueObject

set right before spawning acceptors



17
18
19
# File 'lib/yahns/http_context.rb', line 17

def queue
  @queue
end

Instance Method Details

#__wrap_app(app) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/yahns/http_context.rb', line 47

def __wrap_app(app)
  # input_buffering == false is handled in http_client
  return app if @client_max_body_size == nil

  require_relative 'cap_input'
  return app if @input_buffering == true

  # @input_buffering == false/:lazy
  require_relative 'max_body'
  Yahns::MaxBody.new(app, @client_max_body_size)
end

#after_fork_initObject

call this after forking



43
44
45
# File 'lib/yahns/http_context.rb', line 43

def after_fork_init
  @app = __wrap_app(@yahns_rack.app_after_fork)
end

#errorsObject



76
77
78
# File 'lib/yahns/http_context.rb', line 76

def errors
  @app_defaults["rack.errors"]
end

#errors=(dest) ⇒ Object



72
73
74
# File 'lib/yahns/http_context.rb', line 72

def errors=(dest)
  @app_defaults["rack.errors"] = dest
end

#http_ctx_init(yahns_rack) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yahns/http_context.rb', line 23

def http_ctx_init(yahns_rack)
  @yahns_rack = yahns_rack
  @app_defaults = yahns_rack.app_defaults
  @check_client_connection = false
  @client_body_buffer_size = 8 * 1024
  @client_header_buffer_size = 4000
  @client_max_body_size = 1024 * 1024 # nil => infinity
  @input_buffering = true
  @output_buffering = true
  @persistent_connections = true
  @client_timeout = 15
  @qegg = nil
  @queue = nil

  # Dir.tmpdir can change while running, so leave these as nil
  @input_buffer_tmpdir = nil
  @output_buffer_tmpdir = nil
end

#loggerObject



64
65
66
# File 'lib/yahns/http_context.rb', line 64

def logger
  @app_defaults["rack.logger"]
end

#logger=(l) ⇒ Object

call this immediately after successful accept()/accept4()



60
61
62
# File 'lib/yahns/http_context.rb', line 60

def logger=(l) # cold
  @logger = @app_defaults["rack.logger"] = l
end

#mkinput(client, hs) ⇒ Object



68
69
70
# File 'lib/yahns/http_context.rb', line 68

def mkinput(client, hs)
  (@input_buffering ? Yahns::TeeInput : Yahns::StreamInput).new(client, hs)
end

#tmpio_for(len) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/yahns/http_context.rb', line 80

def tmpio_for(len)
  if len # Content-Length given
    len <= @client_body_buffer_size ? StringIO.new("")
         : Yahns::TmpIO.new(input_buffer_tmpdir)
  else # chunked, unknown length
    mbs = @client_max_body_size
    tmpdir = input_buffer_tmpdir
    mbs ? Yahns::CapInput.new(mbs, tmpdir) : Yahns::TmpIO.new(tmpdir)
  end
end