Class: Factorix::HTTP::CachedResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/factorix/http/cached_response.rb

Overview

Response wrapper for cached data

Provides a simple response object that can be constructed from a cached body string, without requiring an actual HTTP response. Used by CacheDecorator to return cached content with a uniform interface matching Response objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ CachedResponse

Returns a new instance of CachedResponse.

Parameters:

  • body (String)

    cached response body



17
18
19
20
21
# File 'lib/factorix/http/cached_response.rb', line 17

def initialize(body)
  @body = body
  @code = 200
  @headers = {"content-type" => ["application/octet-stream"]}
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



12
13
14
# File 'lib/factorix/http/cached_response.rb', line 12

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



13
14
15
# File 'lib/factorix/http/cached_response.rb', line 13

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



14
15
16
# File 'lib/factorix/http/cached_response.rb', line 14

def headers
  @headers
end

Instance Method Details

#content_lengthInteger

Get content length from body size

Returns:

  • (Integer)

    body size in bytes



34
# File 'lib/factorix/http/cached_response.rb', line 34

def content_length = @body.bytesize

#success?Boolean

Always returns true for cached responses

Since only successful responses are cached, all CachedResponse objects represent successful HTTP interactions.

Returns:

  • (Boolean)

    true



29
# File 'lib/factorix/http/cached_response.rb', line 29

def success? = true