Sha256: 50246cd02d207b25653b665fddf0503676d5bcf5d93ead740a5cdb0f3a3e56dd

Contents?: true

Size: 846 Bytes

Versions: 2

Compression:

Stored size: 846 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.to_i!=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

2 entries across 2 versions & 1 rubygems

Version Path
restfulie-1.0.0.beta5 lib/restfulie/client/feature/conneg_when_unaccepted.rb
restfulie-1.0.0.beta4 lib/restfulie/client/feature/conneg_when_unaccepted.rb