diff --git a/lib/mobvious/strategies/cookie.rb b/lib/mobvious/strategies/cookie.rb index 59a17d2..4cb9388 100644 --- a/lib/mobvious/strategies/cookie.rb +++ b/lib/mobvious/strategies/cookie.rb @@ -41,13 +41,20 @@ def get_device_type(request) # @param request [Rack::Request] # @param response [Rack::Response] def response_callback(request, response) - response_cookie_already_set = !!response.headers["Set-Cookie"] && - !!response.headers["Set-Cookie"]["mobvious.device_type"] - request_cookie = request.cookies['mobvious.device_type'] - # re-set the cookie to renew the expiration date - if request_cookie && !response_cookie_already_set - set_device_type(response, request_cookie) + # Sprockets::StaticAsset has no method :headers + + if response.respond_to? :headers + + response_cookie_already_set = !!response.headers["Set-Cookie"] && + !!response.headers["Set-Cookie"]["mobvious.device_type"] + request_cookie = request.cookies['mobvious.device_type'] + + # re-set the cookie to renew the expiration date + if request_cookie && !response_cookie_already_set + set_device_type(response, request_cookie) + end + end end