user_agent_test_controller.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class UserAgentTestController < ApplicationController
  3. skip_before_action :verify_csrf_token
  4. # GET test/get
  5. def get
  6. process_request('get', 200)
  7. end
  8. # GET test/get_accepted
  9. def accepted
  10. process_request('get', 202)
  11. end
  12. # POST test/post
  13. def post
  14. process_request('post', 201)
  15. end
  16. # PUT test/put
  17. def put
  18. process_request('put', 200)
  19. end
  20. # DELETE test/delete
  21. def delete
  22. process_request('delete', 200)
  23. end
  24. # GET test/redirect
  25. def redirect
  26. redirect_to "#{request.protocol}#{request.host_with_port}/test/get/1?submitted=abc"
  27. end
  28. private
  29. def process_request(type, status)
  30. sleep_time = params[:sec].to_i > 1 ? params[:sec].to_i : 0.1
  31. sleep sleep_time
  32. render json: {
  33. remote_ip: request.remote_ip,
  34. content_type_requested: request.content_type,
  35. method: type,
  36. submitted: params[:submitted]
  37. },
  38. status: status
  39. end
  40. end