Skip to content
This repository has been archived by the owner on Dec 2, 2018. It is now read-only.

Commit

Permalink
Ensure Taps version of OkJson is used to properly encode data.
Browse files Browse the repository at this point in the history
Taps uses a customized version of OkJson to exchange data between the client
and server. This customized version silently converts symbols to strings
as a convience (the original OkJson considers encoding symbols an error since
symbols are not a type supported by JSON).

Rack started using OkJson also to encode data but kept the original symantics.
Since the Taps::Server inherits from Sinatra::Base, and Sinatra::Base includes
Rack::Utils, and Rack::Utils is the namespace where Rack's version of OkJson
is installed this means the Rack version is now being used by taps instead of
the taps version. This means when symbols are encoded an error is generated.

To restore the original behavior this patch explicility references the taps
version of OkJson.

This fixes issue ricardochimal#128.
  • Loading branch information
eric1234 committed Jul 12, 2013
1 parent 93bd272 commit fc2d412
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/taps/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Server < Sinatra::Base
end
if e.kind_of?(Taps::BaseError)
content_type "application/json"
halt 412, OkJson.encode({ 'error_class' => e.class.to_s, 'error_message' => e.message, 'error_backtrace' => e.backtrace.join("\n") })
halt 412, ::OkJson.encode({ 'error_class' => e.class.to_s, 'error_message' => e.message, 'error_backtrace' => e.backtrace.join("\n") })
else
"Taps Server Error: #{e}\n#{e.backtrace}"
end
Expand All @@ -48,7 +48,7 @@ class Server < Sinatra::Base

get '/health' do
content_type 'application/json'
OkJson.encode({ :ok => true })
::OkJson.encode({ :ok => true })
end

get '/' do
Expand Down Expand Up @@ -85,7 +85,7 @@ class Server < Sinatra::Base
end

content_type 'application/json'
OkJson.encode({ :state => stream.to_hash })
::OkJson.encode({ :state => stream.to_hash })
end

post '/sessions/:key/push/table' do
Expand Down Expand Up @@ -154,7 +154,7 @@ class Server < Sinatra::Base
end

content_type 'application/json'
OkJson.encode(tables)
::OkJson.encode(tables)
end

post '/sessions/:key/pull/table_count' do
Expand All @@ -176,13 +176,13 @@ class Server < Sinatra::Base
stream = nil

session.conn do |db|
state = OkJson.decode(params[:state]).symbolize_keys
state = ::OkJson.decode(params[:state]).symbolize_keys
stream = Taps::DataStream.factory(db, state)
encoded_data = stream.fetch.first
end

checksum = Taps::Utils.checksum(encoded_data).to_s
json = OkJson.encode({ :checksum => checksum, :state => stream.to_hash })
json = ::OkJson.encode({ :checksum => checksum, :state => stream.to_hash })

content, content_type_value = Taps::Multipart.create do |r|
r.attach :name => :encoded_data,
Expand Down

0 comments on commit fc2d412

Please sign in to comment.