lib/rack/linkeddata/conneg.rb in rack-linkeddata-0.1.0 vs lib/rack/linkeddata/conneg.rb in rack-linkeddata-0.1.1
- old
+ new
@@ -3,10 +3,11 @@
# Rack middleware for Linked Data content negotiation.
#
# @see http://www4.wiwiss.fu-berlin.de/bizer/pub/LinkedDataTutorial/
class ContentNegotiation
DEFAULT_CONTENT_TYPE = "text/plain" # N-Triples
+ VARY = {'Vary' => 'Accept'}.freeze
# @return [#call]
attr_reader :app
# @return [Hash{Symbol => Object}]
@@ -49,11 +50,16 @@
# @param [Hash{String => Object}] headers
# @param [RDF::Enumerable] body
# @return [Array(Integer, Hash, #each)]
def serialize(env, status, headers, body)
writer, content_type = find_writer(env)
- writer ? [status, headers.merge('Content-Type' => content_type), [writer.dump(body)]] : not_acceptable
+ if writer
+ headers = headers.merge(VARY).merge('Content-Type' => content_type) # FIXME: don't overwrite existing Vary headers
+ [status, headers, [writer.dump(body)]]
+ else
+ not_acceptable
+ end
end
##
# Returns an `RDF::Writer` class for the given `env`.
#
@@ -121,10 +127,10 @@
# Outputs an HTTP `406 Not Acceptable` response.
#
# @param [String, #to_s] message
# @return [Array(Integer, Hash, #each)]
def not_acceptable(message = nil)
- http_error(406, message)
+ http_error(406, message, VARY)
end
##
# Outputs an HTTP `4xx` or `5xx` response.
#