Hi David - got rid of all this stuff from server.rb. Michal had put the
relevant code into respond_to but forgot to push. Its now there in svn
commit: r1000397,
marios
On 23/09/10 00:26, David Lutterkort wrote:
On Mon, 2010-09-20 at 19:52 +0100, [email protected] wrote:
From: marios<[email protected]>
---
server/lib/sinatra/respond_to.rb | 2 +
server/server.rb | 82 ++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/server/lib/sinatra/respond_to.rb b/server/lib/sinatra/respond_to.rb
index f4704ea..829cbe8 100644
--- a/server/lib/sinatra/respond_to.rb
+++ b/server/lib/sinatra/respond_to.rb
@@ -43,6 +43,8 @@ module Sinatra
app.before do
# Let through sinatra image urls in development
next if self.class.development?&& request.path_info =~
%r{/__sinatra__/.*?.png}
+ #FIXME using ?format to do content negotiation for buckets so skip
negotiation here?
+ next if request.path_info =~ (/\/api\/buckets\/*/)
I'd prefer if we changed respond_to so that it never uses the extension
on the URL path's basename to indicate content; instead, use a query
parameter like '?format=xml' to override the Accept header.
Overriding Accept is mostly a convenience for humans (e.g., to look at
XML in a browser)
diff --git a/server/server.rb b/server/server.rb
index 498d3ed..f19c213 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -9,6 +9,7 @@ require 'sinatra/lazy_auth'
require 'erb'
require 'haml'
require 'open3'
+require 'lib/deltacloud/helpers/blob_stream'
configure do
set :raise_errors => false
@@ -355,3 +356,84 @@ collection :keys do
end
end
+
+VALID_RESPONSE_FORMATS = ['xml', 'XML', 'html', 'HTML', 'json', 'JSON']
+#--
+#* F * I * X * M * E - will ultimately use Accept header to do this
+#--
+get '/api/buckets/:bucket/:blob' do
+ response_format = params['format'] unless (params['format'].nil? ||
!VALID_RESPONSE_FORMATS.include?(params['format']))
+ response_format ||= 'html'
This should just go into respond_to
David