File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,12 @@ def error_format(new_format = nil)
122122 new_format ? set ( :error_format , new_format . to_sym ) : settings [ :error_format ]
123123 end
124124
125+ # Specify additional content-types, e.g.:
126+ # content_types :xls => 'application/vnd.ms-excel'
127+ def content_types ( map = { } )
128+ map . any? ? set ( :content_types , map ) : settings [ :content_types ]
129+ end
130+
125131 # Specify the default status code for errors.
126132 def default_error_status ( new_status = nil )
127133 new_status ? set ( :default_error_status , new_status ) : settings [ :default_error_status ]
Original file line number Diff line number Diff line change @@ -248,7 +248,9 @@ def build_middleware
248248 }
249249 end
250250
251- b . use Grape ::Middleware ::Formatter , :default_format => settings [ :default_format ] || :json
251+ b . use Grape ::Middleware ::Formatter ,
252+ :default_format => settings [ :default_format ] || :json ,
253+ :content_types => settings [ :content_types ]
252254
253255 aggregate_setting ( :middleware ) . each do |m |
254256 m = m . dup
Original file line number Diff line number Diff line change @@ -679,6 +679,17 @@ def hello
679679 end
680680 end
681681
682+ describe ".content_types" do
683+ it "sets additional content-type" do
684+ subject . content_types :xls => "application/vnd.ms-excel"
685+ subject . get ( :hello ) do
686+ "some binary content"
687+ end
688+ get '/hello.xls'
689+ last_response . content_type . should == "application/vnd.ms-excel"
690+ end
691+ end
692+
682693 describe ".default_error_status" do
683694 it 'should allow setting default_error_status' do
684695 subject . rescue_from :all
You can’t perform that action at this time.
0 commit comments