Class: Faraday::Env

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/faraday/options.rb

Constant Summary collapse

ContentLength =
'Content-Length'.freeze
StatusesWithoutBody =
Set.new [204, 304]
SuccessfulStatuses =
200..299
MethodsWithBodies =

A Set of HTTP verbs that typically send a body. If no body is set for these requests, the Content-Length header is set to 0.

Set.new [:post, :put, :patch, :options]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(value) ⇒ Object

Public


273
274
275
276
277
278
279
# File 'lib/faraday/options.rb', line 273

def self.from(value)
  env = super(value)
  if value.respond_to?(:custom_members)
    env.custom_members.update(value.custom_members)
  end
  env
end

.member_setObject

Internal


355
356
357
# File 'lib/faraday/options.rb', line 355

def self.member_set
  @member_set ||= Set.new(members)
end

Instance Method Details

#[](key) ⇒ Object

Public


282
283
284
285
286
287
288
# File 'lib/faraday/options.rb', line 282

def [](key)
  if in_member_set?(key)
    super(key)
  else
    custom_members[key]
  end
end

#[]=(key, value) ⇒ Object

Public


291
292
293
294
295
296
297
# File 'lib/faraday/options.rb', line 291

def []=(key, value)
  if in_member_set?(key)
    super(key, value)
  else
    custom_members[key] = value
  end
end

#clear_bodyObject

Public


310
311
312
313
# File 'lib/faraday/options.rb', line 310

def clear_body
  request_headers[ContentLength] = '0'
  self.body = ''
end

#custom_membersObject

Internal


339
340
341
# File 'lib/faraday/options.rb', line 339

def custom_members
  @custom_members ||= {}
end

#in_member_set?(key) ⇒ Boolean

Returns:

  • (Boolean)

345
346
347
# File 'lib/faraday/options.rb', line 345

def in_member_set?(key)
  self.class.member_set.include?(key.to_sym)
end

#inspectObject


325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/faraday/options.rb', line 325

def inspect
  attrs = [nil]
  members.each do |mem|
    if value = send(mem)
      attrs << "@#{mem}=#{value.inspect}"
    end
  end
  if !custom_members.empty?
    attrs << "@custom=#{custom_members.inspect}"
  end
  %(#<#{self.class}#{attrs.join(" ")}>)
end

#needs_body?Boolean

Public

Returns:

  • (Boolean)

305
306
307
# File 'lib/faraday/options.rb', line 305

def needs_body?
  !body && MethodsWithBodies.include?(method)
end

#parallel?Boolean

Public

Returns:

  • (Boolean)

321
322
323
# File 'lib/faraday/options.rb', line 321

def parallel?
  !!parallel_manager
end

#parse_body?Boolean

Public

Returns:

  • (Boolean)

316
317
318
# File 'lib/faraday/options.rb', line 316

def parse_body?
  !StatusesWithoutBody.include?(status)
end

#success?Boolean

Public

Returns:

  • (Boolean)

300
301
302
# File 'lib/faraday/options.rb', line 300

def success?
  SuccessfulStatuses.include?(status)
end