Class: ICAPrb::Server::Services::EchoService

Inherits:
ServiceBase
  • Object
show all
Defined in:
lib/icaprb/server/services.rb

Overview

Sample Service to test the server it will echo the complete request to the client

Instance Attribute Summary

Attributes inherited from ServiceBase

#counter, #is_tag, #max_connections, #options_ttl, #preview_size, #service_id, #service_name, #supported_methods, #timeout, #transfer_complete, #transfer_ignore, #transfer_preview

Instance Method Summary collapse

Methods inherited from ServiceBase

#do_process, #enter, #generate_options_response, #get_the_rest_of_the_data, #got_all_data?, #leave, #set_generic_icap_headers, #supports_preview?

Constructor Details

#initializeEchoService

initializes the EchoService - the name of the echo service is echo



209
210
211
212
# File 'lib/icaprb/server/services.rb', line 209

def initialize
  super('echo',[:request_mod, :response_mod],1024,60,nil,nil,nil,1000)
  @timeout = nil
end

Instance Method Details

#process_request(icap_server, ip, socket, data) ⇒ Object

return the request to the client



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/icaprb/server/services.rb', line 215

def process_request(icap_server,ip,socket,data)
  logger = icap_server.logger
  logger.debug 'Start processing data via echo service...'
  response = ::ICAPrb::Server::Response.new
  response.icap_status_code = 200
  if data[:icap_data][:request_line][:icap_method] == :response_mod
    http_resp_header = data[:http_response_header]
    http_resp_body = data[:http_response_body]
  else
    http_resp_header = data[:http_request_header]
    http_resp_body = data[:http_request_body]
  end

  http_resp_body << get_the_rest_of_the_data(socket) if http_resp_body && !(got_all_data? data)
  response.components << http_resp_header
  response.components << http_resp_body
  response.write_headers_to_socket socket
  if http_resp_body.instance_of? ResponseBody
    socket.write(http_resp_body.to_chunk)
    ::ICAPrb::Server::Response.send_last_chunk(socket,false)
  end
  logger.debug 'Answered request in echo service'
end