Class: OpenID::Server::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/openid/server.rb

Overview

I encode responses in to WebResponses.

If you don’t like WebResponses, you can do your own handling of OpenIDResponses with OpenIDResponse.whichEncoding, OpenIDResponse.encodeToURL, and OpenIDResponse.encodeToKVForm.

Direct Known Subclasses

SigningEncoder

Constant Summary collapse

@@responseFactory =
WebResponse

Instance Method Summary collapse

Instance Method Details

#encode(response) ⇒ Object

Encode a response to a WebResponse.

Raises EncodingError when I can’t figure out how to encode this message.



1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
# File 'lib/openid/server.rb', line 1177

def encode(response)
  encode_as = response.which_encoding
  if encode_as == ENCODE_KVFORM
    wr = @@responseFactory.new(
      HTTP_OK,
      nil,
      response.encode_to_kvform,
    )
    wr.code = HTTP_ERROR if response.is_a?(Exception)
  elsif encode_as == ENCODE_URL
    location = response.encode_to_url
    wr = @@responseFactory.new(
      HTTP_REDIRECT,
      {"location" => location},
    )
  elsif encode_as == ENCODE_HTML_FORM
    wr = @@responseFactory.new(
      HTTP_OK,
      nil,
      response.to_form_markup,
    )
  else
    # Can't encode this to a protocol message.  You should
    # probably render it to HTML and show it to the user.
    raise EncodingError.new(response)
  end

  wr
end