Method: Browser::HTTP::Request#initialize

Defined in:
opal/browser/http/request.rb

#initialize {|request| ... } ⇒ Request

Create a request with the optionally given configuration block.

Yields:

  • (request)

    if the block has a parameter the request is passed otherwise it's instance_exec'd



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'opal/browser/http/request.rb', line 37

def initialize(&block)
  super(transport)

  @parameters   = {}
  @query        = {}
  @headers      = Headers[HEADERS]
  @method       = :get
  @asynchronous = true
  @binary       = false
  @cacheable    = true
  @opened       = false
  @sent         = false
  @completed    = false
  @callbacks    = Hash.new { |h, k| h[k] = [] }

  if block.arity == 0
    instance_exec(&block)
  else
    block.call(self)
  end if block
end