proxy_controller.rb 763 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class ProxyController < ApplicationController
  3. prepend_before_action { authentication_check && authorize! }
  4. # POST /api/v1/proxy
  5. def test
  6. url = 'http://zammad.org'
  7. options = params
  8. options[:open_timeout] = 12
  9. options[:read_timeout] = 24
  10. begin
  11. result = UserAgent.get(
  12. url,
  13. {},
  14. options,
  15. )
  16. rescue => e
  17. render json: {
  18. result: 'failed',
  19. message: e.inspect
  20. }
  21. return
  22. end
  23. if result.success?
  24. render json: {
  25. result: 'success'
  26. }
  27. return
  28. end
  29. render json: {
  30. result: 'failed',
  31. message: result.body || result.error || result.code
  32. }
  33. end
  34. end