user_agent_test_controller.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2025 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. # PUT test/patch
  21. def patch
  22. process_request('patch', 200)
  23. end
  24. # DELETE test/delete
  25. def delete
  26. process_request('delete', 200)
  27. end
  28. # GET test/redirect
  29. def redirect
  30. redirect_to "#{request.protocol}#{request.host_with_port}/test/get/1?submitted=abc", allow_other_host: true
  31. end
  32. private
  33. def process_request(type, status)
  34. sleep_time = params[:sec].to_i > 1 ? params[:sec].to_i : 0.1
  35. sleep sleep_time
  36. render json: {
  37. remote_ip: request.remote_ip,
  38. content_type_requested: request.media_type,
  39. method: type,
  40. body: request.body,
  41. submitted: params[:submitted]
  42. },
  43. status: status
  44. end
  45. end