Class: Hprose::HttpService

Inherits:
Service
  • Object
show all
Defined in:
lib/hprose/httpservice.rb

Constant Summary

Constants included from ResultMode

ResultMode::Normal, ResultMode::Raw, ResultMode::RawWithEndTag, ResultMode::Serialized

Constants included from Tags

Tags::TagArgument, Tags::TagBytes, Tags::TagCall, Tags::TagClass, Tags::TagClosebrace, Tags::TagDate, Tags::TagDouble, Tags::TagEmpty, Tags::TagEnd, Tags::TagError, Tags::TagFalse, Tags::TagFunctions, Tags::TagGuid, Tags::TagInfinity, Tags::TagInteger, Tags::TagList, Tags::TagLong, Tags::TagMap, Tags::TagNaN, Tags::TagNeg, Tags::TagNine, Tags::TagNull, Tags::TagObject, Tags::TagOpenbrace, Tags::TagPoint, Tags::TagPos, Tags::TagQuote, Tags::TagRef, Tags::TagResult, Tags::TagSemicolon, Tags::TagString, Tags::TagTime, Tags::TagTrue, Tags::TagUTC, Tags::TagUTF8Char, Tags::TagZero

Instance Attribute Summary collapse

Attributes inherited from Service

#debug, #on_after_invoke, #on_before_invoke, #on_send_error, #simple

Instance Method Summary collapse

Methods inherited from Service

#add, #add_block, #add_class_methods, #add_filter, #add_function, #add_functions, #add_instance_methods, #add_method, #add_methods, #add_missing_function, #filter, #filter=, #remove_filter

Constructor Details

#initializeHttpService

Returns a new instance of HttpService.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hprose/httpservice.rb', line 27

def initialize
  super
  @crossdomain = false
  @p3p = false
  @get = true
  @origins = {}
  @crossdomain_xml_file = nil
  @crossdomain_xml_content = nil
  @client_access_policy_xml_file = nil
  @client_access_policy_xml_content = nil
  @on_send_header = nil
  @last_modified = Date.today.strftime("%a, %d %b %Y %H:%M:%S GMT")
  @etag = format('"%x:%x"', rand(2147483647), rand(2147483647))
end

Instance Attribute Details

#client_access_policy_xml_contentObject

Returns the value of attribute client_access_policy_xml_content.



48
49
50
# File 'lib/hprose/httpservice.rb', line 48

def client_access_policy_xml_content
  @client_access_policy_xml_content
end

#client_access_policy_xml_fileObject

Returns the value of attribute client_access_policy_xml_file.



47
48
49
# File 'lib/hprose/httpservice.rb', line 47

def client_access_policy_xml_file
  @client_access_policy_xml_file
end

#crossdomainObject

Returns the value of attribute crossdomain.



41
42
43
# File 'lib/hprose/httpservice.rb', line 41

def crossdomain
  @crossdomain
end

#crossdomain_xml_contentObject

Returns the value of attribute crossdomain_xml_content.



46
47
48
# File 'lib/hprose/httpservice.rb', line 46

def crossdomain_xml_content
  @crossdomain_xml_content
end

#crossdomain_xml_fileObject

Returns the value of attribute crossdomain_xml_file.



45
46
47
# File 'lib/hprose/httpservice.rb', line 45

def crossdomain_xml_file
  @crossdomain_xml_file
end

#getObject

Returns the value of attribute get.



43
44
45
# File 'lib/hprose/httpservice.rb', line 43

def get
  @get
end

#on_send_headerObject

Returns the value of attribute on_send_header.



44
45
46
# File 'lib/hprose/httpservice.rb', line 44

def on_send_header
  @on_send_header
end

#p3pObject

Returns the value of attribute p3p.



42
43
44
# File 'lib/hprose/httpservice.rb', line 42

def p3p
  @p3p
end

Instance Method Details

#add_access_control_allow_origin(origin) ⇒ Object



49
50
51
# File 'lib/hprose/httpservice.rb', line 49

def add_access_control_allow_origin(origin)
  @origins[origin] = true
end

#call(context) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/hprose/httpservice.rb', line 81

def call(context)
  unless @client_access_policy_xml_content.nil? then
    result = client_access_policy_xml_handler(context)
    return result if result
  end
  unless @crossdomain_xml_content.nil? then
    result = crossdomain_xml_handler(context)
    return result if result
  end
  header = default_header(context)
  statuscode = 200
  body = ''
  begin
    if (context['REQUEST_METHOD'] == 'GET') and @get then
      body = do_function_list(context)
    elsif (context['REQUEST_METHOD'] == 'POST') then
      body = handle(context['rack.input'].read, context)
    else
      statuscode = 403
      body = 'Forbidden'
    end
  rescue ::Exception => e
    body = do_error(e)
  end
  header['Content-Length'] = body.size.to_s
  return [statuscode, header, [body]]
end

#remove_access_control_allow_origin(origin) ⇒ Object



52
53
54
# File 'lib/hprose/httpservice.rb', line 52

def remove_access_control_allow_origin(origin)
  @origins.delete(origin)
end