lib/rack/linkeddata/conneg.rb in rack-linkeddata-3.0.0 vs lib/rack/linkeddata/conneg.rb in rack-linkeddata-3.1.0
- old
+ new
@@ -30,13 +30,13 @@
##
# @param [#call] app
# @param [Hash{Symbol => Object}] options
# Other options passed to writer.
- # @option options [String] :default (DEFAULT_CONTENT_TYPE) Specific content type
+ # @param [String] :default (DEFAULT_CONTENT_TYPE) Specific content type
# @option options [RDF::Format, #to_sym] :format Specific RDF writer format to use
- def initialize(app, options = {})
+ def initialize(app, options)
@app, @options = app, options
@options[:default] = (@options[:default] || DEFAULT_CONTENT_TYPE).to_s
end
##
@@ -62,20 +62,26 @@
##
# Serializes an `RDF::Enumerable` response into a Rack protocol
# response using HTTP content negotiation rules or a specified Content-Type.
#
+ # Passes parameters from Accept header, and Link header to writer.
+ #
# @param [Hash{String => String}] env
# @param [Integer] status
# @param [Hash{String => Object}] headers
# @param [RDF::Enumerable] body
# @return [Array(Integer, Hash, #each)] Status, Headers and Body
def serialize(env, status, headers, body)
result, content_type = nil, nil
find_writer(env, headers) do |writer, ct, accept_params = {}|
begin
# Passes content_type as writer option to allow parameters to be extracted.
- result, content_type = writer.dump(body, nil, @options.merge(accept_params: accept_params)), ct.split(';').first
+ writer_options = @options.merge(
+ accept_params: accept_params,
+ link: env['HTTP_LINK']
+ )
+ result, content_type = writer.dump(body, nil, **writer_options), ct.split(';').first
break
rescue RDF::WriterError
# Continue to next writer
ct
rescue