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.



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

def app
  @app
end

#app_defaultsObject

Returns the value of attribute app_defaults.



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

def app_defaults
  @app_defaults
end

#check_client_connectionObject

:nodoc:



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

def check_client_connection
  @check_client_connection
end

#client_body_buffer_sizeObject

Returns the value of attribute client_body_buffer_size.



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

def client_body_buffer_size
  @client_body_buffer_size
end

#client_header_buffer_sizeObject

Returns the value of attribute client_header_buffer_size.



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

def client_header_buffer_size
  @client_header_buffer_size
end

#client_max_body_sizeObject

Returns the value of attribute client_max_body_size.



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

def client_max_body_size
  @client_max_body_size
end

#client_timeoutObject

Returns the value of attribute client_timeout.



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

def client_timeout
  @client_timeout
end

#input_buffer_tmpdir=(value) ⇒ Object (writeonly)

Sets the attribute input_buffer_tmpdir

Parameters:

  • value

    the value to set the attribute input_buffer_tmpdir to.



21
22
23
# File 'lib/yahns/http_context.rb', line 21

def input_buffer_tmpdir=(value)
  @input_buffer_tmpdir = value
end

#input_bufferingObject

:lazy, true, false



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

def input_buffering
  @input_buffering
end

#output_buffer_tmpdirObject

Returns the value of attribute output_buffer_tmpdir.



22
23
24
# File 'lib/yahns/http_context.rb', line 22

def output_buffer_tmpdir
  @output_buffer_tmpdir
end

#output_bufferingObject

true, false



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

def output_buffering
  @output_buffering
end

#persistent_connectionsObject

true or false only



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

def persistent_connections
  @persistent_connections
end

#qeggObject

Returns the value of attribute qegg.



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

def qegg
  @qegg
end

#queueObject

set right before spawning acceptors



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

def queue
  @queue
end

Instance Method Details

#__wrap_app(app) ⇒ Object



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

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



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

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

#errorsObject



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

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

#errors=(dest) ⇒ Object



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

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

#http_ctx_init(yahns_rack) ⇒ Object



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

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



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

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

#logger=(l) ⇒ Object

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



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

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

#mkinput(client, hs) ⇒ Object



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

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

#tmpio_for(len, env) ⇒ Object



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

def tmpio_for(len, env)
  # short requests are most common
  if len && len <= @client_body_buffer_size;
    # Can't use binmode, yet: https://bugs.ruby-lang.org/issues/11945
    tmp = StringIO.new(''.dup)
  else # too big or chunked, unknown length
    tmp = @input_buffer_tmpdir
    mbs = @client_max_body_size
    tmp = mbs ? Yahns::CapInput.new(mbs, tmp) : Yahns::TmpIO.new(tmp)
    (env['rack.tempfiles'] ||= []) << tmp
  end
  tmp
end