Sha256: 190ccd5a531d792e38b8acf921ac18689b19ce5c11aa1199a66d674be0fa3632

Contents?: true

Size: 841 Bytes

Versions: 6

Compression:

Stored size: 841 Bytes

Contents

# Retries marshalling to an acceptable media type if
# the server returns with 406: content negotiation. This means looking for
# another media type that both server and client
# understands, picking its converter and using it
# to marshal the original payload again.
#
# To use it, load it in your dsl:
# Restfulie.at("http://localhost:3000/product/2").conneg_when_unaccepted.get
module Restfulie::Client::Feature
  class ConnegWhenUnaccepted
    
  	def execute(chain, request, env)
			resp = chain.continue(request, env)
			return resp if resp.code!=406
		  
			accept = Medie.registry.for(resp.headers["Accept"])
		  return resp if accept.nil?
		  
    	request.with("Content-type", accept)
    	env = env.dup.merge(:body => env[:payload])
    	Restfulie::Client::Feature::SerializeBody.new.execute(chain, request, env)
  	end

  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
restfulie-nosqlite-1.0.4 lib/restfulie/client/feature/conneg_when_unaccepted.rb
restfulie-1.1.1 lib/restfulie/client/feature/conneg_when_unaccepted.rb
restfulie-1.1.0 lib/restfulie/client/feature/conneg_when_unaccepted.rb
restfulie-nosqlite-1.0.3 lib/restfulie/client/feature/conneg_when_unaccepted.rb
restfulie-1.0.3 lib/restfulie/client/feature/conneg_when_unaccepted.rb
restfulie-1.0.0 lib/restfulie/client/feature/conneg_when_unaccepted.rb