Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

basic wanrings on acces control allow origin header value

  • Loading branch information...
commit fa60cb6565c66097840929ead70c25cde4b41d32 1 parent 7e57281
@trevorpower authored
Showing with 15 additions and 2 deletions.
  1. +1 −1  proxy.rb
  2. +14 −1 views/main.coffee
View
2  proxy.rb
@@ -11,7 +11,7 @@ class Proxy < Sinatra::Base
post '/proxy' do
headers 'Content-Type' => 'application/json'
url = request.body.read
- settings.cache.fetch url, 18 do
+ settings.cache.fetch url, 180 do
puts "#{url}: not cached"
fetch(url).to_json
end
View
15 views/main.coffee
@@ -62,9 +62,20 @@ ajaxErrorText = (xhr, status, error) ->
when "parsererror"
"#{error}\n--\n#{xhr.responseText}"
+reportContentType = (name, contentType) ->
+ if contentType.toLowerCase().indexOf('application/json') == -1
+ reportWarning name, "Content-Type: #{contentType}"
+
+reportAllowOrigin = (name, allowOrigin) ->
+ if allowOrigin?
+ if contentType.toLowerCase().indexOf('*') == -1
+ reportWarning name, "Access-Control-Allow-Origin: #{allowOrigin}"
+ else
+ reportWarning name, 'Access-Control-Allow-Origin not set'
+
getResultObject = (name, ajaxResult, xhr) ->
return ajaxResult unless $.type(ajaxResult) == "string"
- reportWarning name, "Content-Type: #{xhr.getResponseHeader('Content-Type')}"
+ reportContentType name, xhr.getResponseHeader('Content-Type')
$.parseJSON(ajaxResult)
getJsonFromProxy = (name, url, success) ->
@@ -77,6 +88,8 @@ getJsonFromProxy = (name, url, success) ->
success: (result, status, xhr) ->
return reportError name, "from proxy: #{result['error']}" if result['error']
reportWarning name, 'resort to proxy'
+ reportContentType name, result.headers['content-type']
+ reportAllowOrigin name, result.headers['access-control-allow-origin']
success(getResultObject(name, result.body, xhr))
error: (xhr, status, error) ->
reportError name, "via proxy: #{ajaxErrorText xhr, status, error}"
Please sign in to comment.
Something went wrong with that request. Please try again.