hprose 1.4.5 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Hprose for Ruby
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/hprose.png)](http://badge.fury.io/rb/hprose)
4
+
3
5
  *Hprose* is a High Performance Remote Object Service Engine.
4
6
 
5
7
  It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.
@@ -14,45 +14,73 @@
14
14
  # #
15
15
  # hprose http service for ruby #
16
16
  # #
17
- # LastModified: Mar 8, 2014 #
17
+ # LastModified: Mar 12, 2014 #
18
18
  # Author: Ma Bingyao <andot@hprose.com> #
19
19
  # #
20
20
  ############################################################
21
21
 
22
- require "hprose/io"
23
- require "hprose/service"
22
+ require 'hprose/io'
23
+ require 'hprose/service'
24
24
 
25
25
  module Hprose
26
26
  class HttpService < Service
27
- attr_accessor :crossdomain
28
- attr_accessor :p3p
29
- attr_accessor :get
30
- attr_accessor :on_send_header
31
27
  def initialize
32
28
  super
33
29
  @crossdomain = false
34
30
  @p3p = false
35
31
  @get = true
32
+ @crossdomain_xml_file = nil
33
+ @crossdomain_xml_content = nil
34
+ @client_access_policy_xml_file = nil
35
+ @client_access_policy_xml_content = nil
36
36
  @on_send_header = nil
37
37
  end
38
+ attr_accessor :crossdomain
39
+ attr_accessor :p3p
40
+ attr_accessor :get
41
+ attr_accessor :on_send_header
42
+ attr_reader :crossdomain_xml_file
43
+ attr_reader :crossdomain_xml_content
44
+ attr_reader :client_access_policy_xml_file
45
+ attr_reader :client_access_policy_xml_content
46
+ def crossdomain_xml_file=(filepath)
47
+ @crossdomain_xml_file = filepath
48
+ f = File.open(filepath)
49
+ begin
50
+ @crossdomain_xml_content = f.read
51
+ ensure
52
+ f.close
53
+ end
54
+ end
55
+ def crossdomain_xml_content=(content)
56
+ @crossdomain_xml_file = nil
57
+ @crossdomain_xml_content = content
58
+ end
59
+ def client_access_policy_xml_file=(filepath)
60
+ @client_access_policy_xml_file = filepath
61
+ f = File.open(filepath)
62
+ begin
63
+ @client_access_policy_xml_content = f.read
64
+ ensure
65
+ f.close
66
+ end
67
+ end
68
+ def client_access_policy_xml_content=(content)
69
+ @client_access_policy_xml_file = nil
70
+ @client_access_policy_xml_content = content
71
+ end
38
72
  def call(context)
39
- header = {'Content-Type' => 'text/plain'}
40
- header['P3P'] = 'CP="CAO DSP COR CUR ADM DEV TAI PSA PSD ' +
41
- 'IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi ' +
42
- 'PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT ' +
43
- 'STA POL HEA PRE GOV"' if @p3p
44
- if @crossdomain then
45
- origin = context["HTTP_ORIGIN"]
46
- if (origin and origin != "null") then
47
- header['Access-Control-Allow-Origin'] = origin
48
- header['Access-Control-Allow-Credentials'] = 'true'
49
- else
50
- header['Access-Control-Allow-Origin'] = '*'
51
- end
73
+ unless @client_access_policy_xml_content.nil? then
74
+ result = client_access_policy_xml_handler(context)
75
+ return result if result
76
+ end
77
+ unless @crossdomain_xml_content.nil? then
78
+ result = crossdomain_xml_handler(context)
79
+ return result if result
52
80
  end
81
+ header = default_header(context)
53
82
  begin
54
83
  statuscode = 200
55
- @on_send_header.call(header) unless @on_send_header.nil?
56
84
  if (context['REQUEST_METHOD'] == 'GET') and @get then
57
85
  body = do_function_list
58
86
  elsif (context['REQUEST_METHOD'] == 'POST') then
@@ -72,5 +100,56 @@ module Hprose
72
100
  session = context['rack.session'] ? context['rack.session'] : {}
73
101
  ((arity > 0) and (args.length + 1 == arity)) ? args + [session] : args
74
102
  end
103
+ private
104
+ def crossdomain_xml_handler(context)
105
+ path = (context['SCRIPT_NAME'] << context['PATH_INFO']).downcase
106
+ if path == '/crossdomain.xml' then
107
+ if context['HTTP_IF_MODIFIED_SINCE'] == @last_modified and
108
+ context['HTTP_IF_NONE_MATCH'] == @etag then
109
+ return [304, {}, ['']]
110
+ else
111
+ header = {'Content-Type' => 'text/xml',
112
+ 'Last-Modified' => @last_modified,
113
+ 'Etag' => @etag,
114
+ 'Content-Length' => @crossdomain_xml_content.size.to_s}
115
+ return [200, header, [@crossdomain_xml_content]]
116
+ end
117
+ end
118
+ return false
119
+ end
120
+ def client_access_policy_xml_handler(context)
121
+ path = (context['SCRIPT_NAME'] << context['PATH_INFO']).downcase
122
+ if path == '/clientaccesspolicy.xml' then
123
+ if context['HTTP_IF_MODIFIED_SINCE'] == @last_modified and
124
+ context['HTTP_IF_NONE_MATCH'] == @etag then
125
+ return [304, {}, ['']]
126
+ else
127
+ header = {'Content-Type' => 'text/xml',
128
+ 'Last-Modified' => @last_modified,
129
+ 'Etag' => @etag,
130
+ 'Content-Length' => @client_access_policy_xml_content.size.to_s}
131
+ return [200, header, [@client_access_policy_xml_content]]
132
+ end
133
+ end
134
+ return false
135
+ end
136
+ def default_header(context)
137
+ header = {'Content-Type' => 'text/plain'}
138
+ header['P3P'] = 'CP="CAO DSP COR CUR ADM DEV TAI PSA PSD ' +
139
+ 'IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi ' +
140
+ 'PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT ' +
141
+ 'STA POL HEA PRE GOV"' if @p3p
142
+ if @crossdomain then
143
+ origin = context['HTTP_ORIGIN']
144
+ if (origin and origin != 'null') then
145
+ header['Access-Control-Allow-Origin'] = origin
146
+ header['Access-Control-Allow-Credentials'] = 'true'
147
+ else
148
+ header['Access-Control-Allow-Origin'] = '*'
149
+ end
150
+ end
151
+ @on_send_header.call(header, context) unless @on_send_header.nil?
152
+ return header
153
+ end
75
154
  end # class HttpService
76
155
  end # module Hprose
@@ -690,7 +690,6 @@ module Hprose
690
690
  @stream.write(usec.modulo(1000).to_s.rjust(3, '0')) if usec % 1000 > 0
691
691
  end
692
692
  end
693
- protected
694
693
  def write_ref(obj)
695
694
  return @refer.write(@stream, obj)
696
695
  end
@@ -14,7 +14,7 @@
14
14
  # #
15
15
  # hprose tcp server for ruby #
16
16
  # #
17
- # LastModified: Mar 11, 2014 #
17
+ # LastModified: Mar 12, 2014 #
18
18
  # Author: Ma Bingyao <andot@hprose.com> #
19
19
  # #
20
20
  ############################################################
@@ -37,18 +37,7 @@ module Hprose
37
37
  end
38
38
  @sockets = nil
39
39
  end
40
- def host
41
- @host
42
- end
43
- def host=(host)
44
- @host = host
45
- end
46
- def port
47
- @port
48
- end
49
- def port=(port)
50
- @port = port
51
- end
40
+ attr_accessor :host, :port
52
41
  def start
53
42
  begin
54
43
  @sockets = Socket.tcp_server_sockets(@host, @port)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hprose
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.5
4
+ version: 1.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-11 00:00:00.000000000 Z
12
+ date: 2014-03-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: andot@hprose.com