lib/helper.rb in opentox-ruby-1.0.2 vs lib/helper.rb in opentox-ruby-2.0.0
- old
+ new
@@ -42,58 +42,55 @@
return env['REQUEST_URI'] =~ /\/login$/
end
def uri_available?(urlStr)
url = URI.parse(urlStr)
- unless @subjectid
- Net::HTTP.start(url.host, url.port) do |http|
- return http.head(url.request_uri).code == "200"
- end
- else
- Net::HTTP.start(url.host, url.port) do |http|
- return http.post(url.request_uri, "subjectid=#{@subjectid}").code == "202"
- end
+ Net::HTTP.start(url.host, url.port) do |http|
+ return http.head("#{url.request_uri}?subjectid=#{CGI.escape @subjectid}").code == "200"
end
end
-end
-
-before do
- unless !AA_SERVER or login_requests or CONFIG[:authorization][:free_request].include?(env['REQUEST_METHOD'])
+ def get_subjectid
begin
subjectid = nil
subjectid = session[:subjectid] if session[:subjectid]
subjectid = params[:subjectid] if params[:subjectid] and !subjectid
subjectid = request.env['HTTP_SUBJECTID'] if request.env['HTTP_SUBJECTID'] and !subjectid
subjectid = request.cookies["subjectid"] unless subjectid
# see http://rack.rubyforge.org/doc/SPEC.html
subjectid = CGI.unescape(subjectid) if subjectid.include?("%23")
@subjectid = subjectid
rescue
- #LOGGER.debug "OpenTox ruby api wrapper: helper before filter: NO subjectid for URI: #{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}"
- subjectid = ""
+ subjectid = nil
end
- @subjectid = subjectid
- protected!(subjectid)
-
- extension = File.extname(request.path_info) # params[:id] is not yet available
+ end
+ def get_extension
+ extension = File.extname(request.path_info)
unless extension.empty?
- #request.path_info.sub!(/\.#{extension}$/,'')
- case extension
- when "html"
- @accept = 'text/html'
- when "yaml"
- @accept = 'application/x-yaml'
- when "csv"
- @accept = 'text/csv'
- when "rdfxml"
- @accept = 'application/rdf+xml'
- when "xls"
- @accept = 'application/ms-excel'
- else
- halt 404, "File format #{extension} not supported."
- end
- end
-
+ case extension.gsub(".","")
+ when "html"
+ @accept = 'text/html'
+ when "yaml"
+ @accept = 'application/x-yaml'
+ when "csv"
+ @accept = 'text/csv'
+ when "rdfxml"
+ @accept = 'application/rdf+xml'
+ when "xls"
+ @accept = 'application/ms-excel'
+ when "css"
+ @accept = 'text/css'
+ else
+ # halt 404, "File format #{extension} not supported."
+ end
+ end
+ end
+end
+
+before do
+ @subjectid = get_subjectid()
+ @accept = get_extension()
+ unless !AA_SERVER or login_requests or CONFIG[:authorization][:free_request].include?(env['REQUEST_METHOD'])
+ protected!(@subjectid)
end
end