Class List Method List File List

# Class: VertxWebClient::HttpResponse

Inherits:
  Object
  - Object
  - VertxWebClient::HttpResponse
  show all
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb

## Overview

An HTTP response.

The usual HTTP response attributes are available:

- #status_code the HTTP status code
- #status_message the HTTP status message
- #headers the HTTP headers
- #version the HTTP version

The body of the response is returned by #body decoded as the format specified by the VertxWebCommon::BodyCodec that built the response.

Keep in mind that using this `HttpResponse` impose to fully buffer the response body and should be used for payload that can fit in memory.

## Instance Method Summary (collapse)

- - (Object) body
  The response body in the format it was decoded.
- - (::Vertx::Buffer) body_as_buffer
  The response body decoded as a , or null if a codec other than was used.
- - (Object) body_as_json(type = nil)
  The response body decoded as the specified type with the Jackson mapper, or null if a codec other than was used.
- - (Array<String,Object>) body_as_json_array
  The response body decoded as a , or null if a codec other than was used.
- - (Hash{String => Object}) body_as_json_object
  The response body decoded as , or null if a codec other than was used.
- - (String) body_as_string(encoding = nil)
  The response body decoded as a String given a specific encoding, or null if a codec other than was used.
- - (Array<String>) cookies
  The Set-Cookie headers (including trailers).
- - (Array<String>) followed_redirects
  The list of all followed redirects, including the final location.
- - (String) get_header(headerName = nil)
  Return the first header value with the specified name.
- - (String) get_trailer(trailerName = nil)
  Return the first trailer value with the specified name.
- - (::Vertx::MultiMap) headers
  The headers.
- - (Fixnum) status_code
  The status code of the response.
- - (String) status_message
  The status message of the response.
- - (::Vertx::MultiMap) trailers
  The trailers.
- - (:HTTP_1_0, ...) version
  The version of the response.

## Instance Method Details

### - (`Object`) body

Returns the response body in the format it was decoded.

Returns:

- (`Object`) —
  the response body in the format it was decoded.

Raises:

- (`ArgumentError`)

    112
    113
    114
    115
    116
    117
    118
    119
    120
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 112

    def body
      if !block_given?
        if @cached_body != nil
          return @cached_body
        end
        return @cached_body = @j_arg_T.wrap(@j_del.java_method(:body, []).call())
      end
      raise ArgumentError, "Invalid arguments when calling body()"
    end

### - (`::Vertx::Buffer`) body_as_buffer

Returns the response body decoded as a , or `null` if a codec other than was used

Returns:

- (`::Vertx::Buffer`) —
  the response body decoded as a , or `null` if a codec other than was used

Raises:

- (`ArgumentError`)

    122
    123
    124
    125
    126
    127
    128
    129
    130
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 122

    def body_as_buffer
      if !block_given?
        if @cached_body_as_buffer != nil
          return @cached_body_as_buffer
        end
        return @cached_body_as_buffer = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:bodyAsBuffer, []).call(),::Vertx::Buffer)
      end
      raise ArgumentError, "Invalid arguments when calling body_as_buffer()"
    end

### - (`Object`) body_as_json(type = nil)

Returns the response body decoded as the specified `type` with the Jackson mapper, or `null` if a codec other than was used

Parameters:

- type (`Nil`) (defaults to: `nil`)

Returns:

- (`Object`) —
  the response body decoded as the specified `type` with the Jackson mapper, or `null` if a codec other than was used

Raises:

- (`ArgumentError`)

    176
    177
    178
    179
    180
    181
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 176

    def body_as_json(type=nil)
      if type.class == Class && !block_given?
        return ::Vertx::Util::Utils.v_type_of(type).wrap(@j_del.java_method(:bodyAsJson, [Java::JavaLang::Class.java_class]).call(::Vertx::Util::Utils.j_class_of(type)))
      end
      raise ArgumentError, "Invalid arguments when calling body_as_json(#{type})"
    end

### - (`Array<String,Object>`) body_as_json_array

Returns the response body decoded as a , or `null` if a codec other than was used

Returns:

- (`Array<String,Object>`) —
  the response body decoded as a , or `null` if a codec other than was used

Raises:

- (`ArgumentError`)

    165
    166
    167
    168
    169
    170
    171
    172
    173
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 165

    def body_as_json_array
      if !block_given?
        if @cached_body_as_json_array != nil
          return @cached_body_as_json_array
        end
        return @cached_body_as_json_array = @j_del.java_method(:bodyAsJsonArray, []).call() != nil ? JSON.parse(@j_del.java_method(:bodyAsJsonArray, []).call().encode) : nil
      end
      raise ArgumentError, "Invalid arguments when calling body_as_json_array()"
    end

### - (`Hash{String => Object}`) body_as_json_object

Returns the response body decoded as , or `null` if a codec other than was used

Returns:

- (`Hash{String => Object}`) —
  the response body decoded as , or `null` if a codec other than was used

Raises:

- (`ArgumentError`)

    155
    156
    157
    158
    159
    160
    161
    162
    163
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 155

    def body_as_json_object
      if !block_given?
        if @cached_body_as_json_object != nil
          return @cached_body_as_json_object
        end
        return @cached_body_as_json_object = @j_del.java_method(:bodyAsJsonObject, []).call() != nil ? JSON.parse(@j_del.java_method(:bodyAsJsonObject, []).call().encode) : nil
      end
      raise ArgumentError, "Invalid arguments when calling body_as_json_object()"
    end

### - (`String`) body_as_string(encoding = nil)

Returns the response body decoded as a `String` given a specific `encoding`, or `null` if a codec other than was used

Parameters:

- encoding (`String`) (defaults to: `nil`)

Returns:

- (`String`) —
  the response body decoded as a `String` given a specific `encoding`, or `null` if a codec other than was used

Raises:

- (`ArgumentError`)

    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 143

    def body_as_string(encoding=nil)
      if !block_given? && encoding == nil
        if @cached_body_as_string != nil
          return @cached_body_as_string
        end
        return @cached_body_as_string = @j_del.java_method(:bodyAsString, []).call()
      elsif encoding.class == String && !block_given?
        return @j_del.java_method(:bodyAsString, [Java::java.lang.String.java_class]).call(encoding)
      end
      raise ArgumentError, "Invalid arguments when calling body_as_string(#{encoding})"
    end

### - (`Array<String>`) cookies

Returns the Set-Cookie headers (including trailers)

Returns:

- (`Array<String>`) —
  the Set-Cookie headers (including trailers)

Raises:

- (`ArgumentError`)

    102
    103
    104
    105
    106
    107
    108
    109
    110
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 102

    def cookies
      if !block_given?
        if @cached_cookies != nil
          return @cached_cookies
        end
        return @cached_cookies = @j_del.java_method(:cookies, []).call().to_a.map { |elt| elt }
      end
      raise ArgumentError, "Invalid arguments when calling cookies()"
    end

### - (`Array<String>`) followed_redirects

Returns the list of all followed redirects, including the final location.

Returns:

- (`Array<String>`) —
  the list of all followed redirects, including the final location.

Raises:

- (`ArgumentError`)

    132
    133
    134
    135
    136
    137
    138
    139
    140
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 132

    def followed_redirects
      if !block_given?
        if @cached_followed_redirects != nil
          return @cached_followed_redirects
        end
        return @cached_followed_redirects = @j_del.java_method(:followedRedirects, []).call().to_a.map { |elt| elt }
      end
      raise ArgumentError, "Invalid arguments when calling followed_redirects()"
    end

### - (`String`) get_header(headerName = nil)

Return the first header value with the specified name

Parameters:

- headerName (`String`) (defaults to: `nil`) —
  the header name

Returns:

- (`String`) —
  the header value

Raises:

- (`ArgumentError`)

    76
    77
    78
    79
    80
    81
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 76

    def get_header(headerName=nil)
      if headerName.class == String && !block_given?
        return @j_del.java_method(:getHeader, [Java::java.lang.String.java_class]).call(headerName)
      end
      raise ArgumentError, "Invalid arguments when calling get_header(#{headerName})"
    end

### - (`String`) get_trailer(trailerName = nil)

Return the first trailer value with the specified name

Parameters:

- trailerName (`String`) (defaults to: `nil`) —
  the trailer name

Returns:

- (`String`) —
  the trailer value

Raises:

- (`ArgumentError`)

    95
    96
    97
    98
    99
    100
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 95

    def get_trailer(trailerName=nil)
      if trailerName.class == String && !block_given?
        return @j_del.java_method(:getTrailer, [Java::java.lang.String.java_class]).call(trailerName)
      end
      raise ArgumentError, "Invalid arguments when calling get_trailer(#{trailerName})"
    end

### - (`::Vertx::MultiMap`) headers

Returns the headers

Returns:

- (`::Vertx::MultiMap`) —
  the headers

Raises:

- (`ArgumentError`)

    64
    65
    66
    67
    68
    69
    70
    71
    72
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 64

    def headers
      if !block_given?
        if @cached_headers != nil
          return @cached_headers
        end
        return @cached_headers = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:headers, []).call(),::Vertx::MultiMap)
      end
      raise ArgumentError, "Invalid arguments when calling headers()"
    end

### - (`Fixnum`) status_code

Returns the status code of the response

Returns:

- (`Fixnum`) —
  the status code of the response

Raises:

- (`ArgumentError`)

    44
    45
    46
    47
    48
    49
    50
    51
    52
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 44

    def status_code
      if !block_given?
        if @cached_status_code != nil
          return @cached_status_code
        end
        return @cached_status_code = @j_del.java_method(:statusCode, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling status_code()"
    end

### - (`String`) status_message

Returns the status message of the response

Returns:

- (`String`) —
  the status message of the response

Raises:

- (`ArgumentError`)

    54
    55
    56
    57
    58
    59
    60
    61
    62
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 54

    def status_message
      if !block_given?
        if @cached_status_message != nil
          return @cached_status_message
        end
        return @cached_status_message = @j_del.java_method(:statusMessage, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling status_message()"
    end

### - (`::Vertx::MultiMap`) trailers

Returns the trailers

Returns:

- (`::Vertx::MultiMap`) —
  the trailers

Raises:

- (`ArgumentError`)

    83
    84
    85
    86
    87
    88
    89
    90
    91
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 83

    def trailers
      if !block_given?
        if @cached_trailers != nil
          return @cached_trailers
        end
        return @cached_trailers = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:trailers, []).call(),::Vertx::MultiMap)
      end
      raise ArgumentError, "Invalid arguments when calling trailers()"
    end

### - (`:HTTP_1_0`, ...) version

Returns the version of the response

Returns:

- (`:HTTP_1_0`, `:HTTP_1_1`, `:HTTP_2`) —
  the version of the response

Raises:

- (`ArgumentError`)

    34
    35
    36
    37
    38
    39
    40
    41
    42
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web-client/http_response.rb', line 34

    def version
      if !block_given?
        if @cached_version != nil
          return @cached_version
        end
        return @cached_version = @j_del.java_method(:version, []).call().name.intern
      end
      raise ArgumentError, "Invalid arguments when calling version()"
    end