lib/angelo/responder.rb in angelo-0.1.5 vs lib/angelo/responder.rb in angelo-0.1.6

- old
+ new

@@ -44,10 +44,11 @@ @base.responder = self end def request= request @params = nil + @redirect = nil @request = request handle_request respond end @@ -119,21 +120,24 @@ JSON.parse @body if respond_with? :json # for the raises @body when Hash raise 'html response requires String' if respond_with? :html @body.to_json if respond_with? :json + when NilClass + EMPTY_STRING end - Angelo.log @connection, @request, nil, :ok, @body.size - @connection.respond :ok, headers, @body + + status = @redirect.nil? ? :ok : :moved_permanently + headers LOCATION_HEADER_KEY => @redirect if @redirect + + Angelo.log @connection, @request, nil, status, @body.size + @connection.respond status, headers, @body rescue => e handle_error e, :internal_server_error, false end def redirect url - Angelo.log @connection, @request, nil, :moved_permanently, 0 - @connection.respond :moved_permanently, headers(LOCATION_HEADER_KEY => url), '' - rescue => e - handle_error e, :internal_server_error, false + @redirect = url end end end