riddl 1.0.12 → 1.0.14

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6755641198fcdf1ec742d707109514d224a582ad0d09e148a7d2b8bf98f2f292
4
- data.tar.gz: 11b7c505a67f971b723c545b6c7e3a83b12c85b2b13b2e228fd891b4a077b571
3
+ metadata.gz: ad59966187ba048180bb734ff13f6cd32ec4afefe92301ce9215a70dd2a2d3e0
4
+ data.tar.gz: 3aa43b4e9af2ecb5f4eaffa703dd55f44383518ae157d720bad2c9db0a9b48c4
5
5
  SHA512:
6
- metadata.gz: fc39f83807cd69c212578dc2520488ccd8b2336ebcc73fe5d42a5562028141f0c8ced512efa87e430e703ffdd54686c8d53957ba7bcc9a39d0366e5fc7a64cae
7
- data.tar.gz: e817630e2ed9cfb4be792bae5951aa2c8ef0201a47a59389fd06ec37a02a2ca784e18cecfd0ae5e14c86059db51864ec9319a3cf879f9c8e2b6f549bf21ab21f
6
+ metadata.gz: 24dfe6af55d83570e06a0a76c8337cc3d6a32db4b8db7626c13a3d7c7d12c1a4d2a141b5595556c6cfe9a5c0d92e351f3e6e14cf8b842c4e9334ba826a395687
7
+ data.tar.gz: a3c9fc40d71d9e16e4386832880d2b10da7e0dc4ac54bc734b6683f1c14f7bfefa67f91a7d87571f9ec798c05fc60badb8eaec6e2b7cc05f83c2d3f1183273c2
@@ -353,12 +353,12 @@ unless Module.constants.include?('CLIENT_INCLUDED')
353
353
  path += "?#{qs}" unless qs == ''
354
354
  uri = url.scheme + '://' + url.host + ':' + url.port.to_s + path
355
355
 
356
- tmp = Protocols::HTTP::Generator.new(parameters,headers).generate(:input)
356
+ parts = Protocols::HTTP::Generator.new(parameters,headers).generate(:input)
357
357
 
358
358
  opts = {
359
359
  :method => riddl_method,
360
360
  :headers => headers,
361
- :body => tmp.read,
361
+ :body => Protocols::HTTP::Generator.merge(parts),
362
362
  :ssl_verifypeer => false
363
363
  # :followlocation => true
364
364
  }
@@ -428,9 +428,10 @@ unless Module.constants.include?('CLIENT_INCLUDED')
428
428
  path = (path.strip == '' ? '/' : path)
429
429
  path += "?#{qs}" unless qs == ''
430
430
  super method, true, true, path, headers
431
- tmp = Protocols::HTTP::Generator.new(parameters,self).generate(:input)
432
- self.content_length = tmp.size
433
- self.body_stream = tmp
431
+ parts = Protocols::HTTP::Generator.new(parameters,self).generate(:input)
432
+ merged = Protocols::HTTP::Generator.merge(parts)
433
+ self.content_length = merged.bytesize
434
+ self.body_stream = StringIO.new(merged)
434
435
  end
435
436
 
436
437
  def supply_default_content_type
@@ -5,12 +5,49 @@ require 'stringio'
5
5
  module Riddl
6
6
  module Protocols
7
7
  module HTTP
8
+
9
+ class StreamingBody
10
+ CHUNK_SIZE = 1 << 16 # 64 KiB
11
+
12
+ def initialize(parts)
13
+ @parts = parts
14
+ end
15
+
16
+ def each
17
+ @parts.each do |part|
18
+ if part.respond_to?(:read)
19
+ part.rewind if part.respond_to?(:rewind)
20
+ yield chunk while (chunk = part.read(CHUNK_SIZE))
21
+ else
22
+ yield part.to_s
23
+ end
24
+ end
25
+ end
26
+
27
+ def close
28
+ @parts.each do |part|
29
+ part.close if part.respond_to?(:close) && !part.is_a?(String)
30
+ end
31
+ end
32
+ end
33
+
8
34
  class Generator
9
35
  def initialize(params,headers)
10
36
  @params = params
11
37
  @headers = headers
12
38
  end
13
39
 
40
+ def self.merge(parts)
41
+ parts.map do |p|
42
+ if p.respond_to?(:read)
43
+ p.rewind if p.respond_to?(:rewind)
44
+ p.read
45
+ else
46
+ p.to_s
47
+ end
48
+ end.join
49
+ end
50
+
14
51
  def generate(mode=:output)
15
52
  if @params.is_a?(Array) && @params.length == 1
16
53
  body(@params[0],mode)
@@ -21,29 +58,26 @@ module Riddl
21
58
  else
22
59
  if mode == :output
23
60
  @headers['Content-Type'] = 'text/plain'
24
- StringIO.new('','r+b')
25
- else
26
- StringIO.new('','r+b')
27
61
  end
62
+ []
28
63
  end
29
64
  end
30
65
 
31
66
  def body(r,mode)
32
- tmp = StringIO.new('','r+b')
67
+ parts = []
33
68
  case r
34
69
  when Riddl::Parameter::Simple
35
70
  if mode == :output
36
- tmp.write r.value
71
+ parts << r.value
37
72
  @headers['Content-Type'] = 'text/plain'
38
73
  @headers['Content-ID'] = r.name
39
74
  @headers['RIDDL-TYPE'] = 'simple'
40
- end
41
- if mode == :input
75
+ else
42
76
  @headers['Content-Type'] = 'application/x-www-form-urlencoded'
43
- tmp.write Riddl::Protocols::Utils::escape(r.name) + '=' + Riddl::Protocols::Utils::escape(r.value)
77
+ parts << Riddl::Protocols::Utils::escape(r.name) + '=' + Riddl::Protocols::Utils::escape(r.value)
44
78
  end
45
79
  when Riddl::Parameter::Complex
46
- tmp.write(r.value.respond_to?(:read) ? r.value.read : r.value)
80
+ parts << r.value
47
81
  @headers['Content-Type'] = r.mimetype + r.mimextra
48
82
  @headers['RIDDL-TYPE'] = 'complex'
49
83
  if r.filename.nil?
@@ -52,14 +86,12 @@ module Riddl
52
86
  @headers['Content-Disposition'] = "riddl-data; name=\"#{r.name}\"; filename=\"#{r.filename}\""
53
87
  end
54
88
  end
55
- tmp.flush
56
- tmp.rewind
57
- tmp
89
+ parts
58
90
  end
59
91
  private :body
60
92
 
61
93
  def multipart(mode)
62
- tmp = StringIO.new('','r+b')
94
+ parts = []
63
95
  scount = ccount = 0
64
96
  @params.each do |r|
65
97
  case r
@@ -78,38 +110,35 @@ module Riddl
78
110
  res << Riddl::Protocols::Utils::escape(r.name) + '=' + Riddl::Protocols::Utils::escape(r.value)
79
111
  end
80
112
  end
81
- tmp.write res.join('&')
113
+ parts << res.join('&')
82
114
  else
83
115
  if scount + ccount > 0
84
116
  @headers['Content-Type'] = "multipart/#{mode == :input ? 'form-data' : 'mixed'}; boundary=\"#{BOUNDARY}\""
85
117
  @params.each do |r|
86
118
  case r
87
119
  when Riddl::Parameter::Simple
88
- tmp.write '--' + BOUNDARY + EOL
89
- tmp.write 'RIDDL-TYPE: simple' + EOL
90
- tmp.write "Content-Disposition: form-data; name=\"#{r.name}\"" + EOL
91
- tmp.write EOL
92
- tmp.write r.value
93
- tmp.write EOL
120
+ parts << '--' + BOUNDARY + EOL +
121
+ 'RIDDL-TYPE: simple' + EOL +
122
+ "Content-Disposition: form-data; name=\"#{r.name}\"" + EOL +
123
+ EOL +
124
+ r.value.to_s +
125
+ EOL
94
126
  when Riddl::Parameter::Complex
95
- tmp.write '--' + BOUNDARY + EOL
96
- tmp.write 'RIDDL-TYPE: complex' + EOL
97
- tmp.write "Content-Disposition: form-data; name=\"#{r.name}\""
98
- #tmp.write r.filename.nil? ? '; filename=""' + EOL : "; filename=\"#{r.filename}\"" + EOL
99
- tmp.write r.filename.nil? ? EOL : "; filename=\"#{r.filename}\"" + EOL
100
- tmp.write 'Content-Transfer-Encoding: binary' + EOL
101
- tmp.write 'Content-Type: ' + r.mimetype + r.mimextra + EOL
102
- tmp.write EOL
103
- tmp.write(r.value.respond_to?(:read) ? r.value.read : r.value)
104
- tmp.write EOL
127
+ parts << '--' + BOUNDARY + EOL +
128
+ 'RIDDL-TYPE: complex' + EOL +
129
+ "Content-Disposition: form-data; name=\"#{r.name}\"" +
130
+ (r.filename.nil? ? EOL : "; filename=\"#{r.filename}\"" + EOL) +
131
+ 'Content-Transfer-Encoding: binary' + EOL +
132
+ 'Content-Type: ' + r.mimetype + r.mimextra + EOL +
133
+ EOL
134
+ parts << r.value
135
+ parts << EOL
105
136
  end
106
137
  end
107
- tmp.write '--' + BOUNDARY + '--' + EOL
138
+ parts << '--' + BOUNDARY + '--' + EOL
108
139
  end
109
140
  end
110
- tmp.flush
111
- tmp.rewind
112
- tmp
141
+ parts
113
142
  end
114
143
  private :multipart
115
144
 
@@ -21,8 +21,6 @@ module Riddl
21
21
 
22
22
  def parse_content(input,ctype,content_length,content_disposition,content_id,riddl_type)
23
23
  #{{{
24
- # fixing for chunked?
25
-
26
24
  ctype = nil if riddl_type == 'simple'
27
25
  filename = content_disposition[/ filename="?([^\";]*)"?/ni, 1]
28
26
  name = content_disposition[/ name="?([^\";]*)"?/ni, 1] || content_id
@@ -35,6 +33,8 @@ module Riddl
35
33
  end
36
34
 
37
35
  if content_length == 0
36
+ # should never happen normally, but leave it in, as sombody might
37
+ # decide to use parse_content independently
38
38
  bufsize = 16384
39
39
  until input.eof?
40
40
  c = input.read(bufsize)
@@ -177,6 +177,9 @@ module Riddl
177
177
  # such as when using plain CGI under Apache
178
178
  end
179
179
 
180
+ # fixing for chunked
181
+ content_length = content_length && content_length.to_i > 0 ? content_length.to_i : input.size
182
+
180
183
  media_type = content_type && content_type.split(/\s*[;,]\s*/, 2).first.downcase
181
184
  @params = Riddl::Parameter::Array.new
182
185
  parse_nested_query(query_string,:query)
@@ -322,13 +322,16 @@ module Riddl
322
322
  @riddl_status = 404 # client requests wrong path
323
323
  end
324
324
  if @riddl_exe
325
- @riddl_res.write Protocols::HTTP::Generator.new(@riddl_exe.response,@riddl_res).generate.read
325
+ parts = Protocols::HTTP::Generator.new(@riddl_exe.response,@riddl_res).generate
326
326
  @riddl_exe.headers.each do |n,h|
327
327
  @riddl_res[n] = h
328
328
  end
329
+ @riddl_res.status = @riddl_status
330
+ [@riddl_status, @riddl_res.headers, Protocols::HTTP::StreamingBody.new(parts)]
331
+ else
332
+ @riddl_res.status = @riddl_status
333
+ @riddl_res.finish
329
334
  end
330
- @riddl_res.status = @riddl_status
331
- @riddl_res.finish
332
335
  end #}}}
333
336
 
334
337
  def process_out(pout)# {{{
data/riddl.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "riddl"
3
- s.version = "1.0.12"
3
+ s.version = "1.0.14"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0-or-later"
6
6
  s.summary = "Restful Interface Description and Declaration Language: tools and client/server libs"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riddl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen 'eTM' Mangler
@@ -539,7 +539,7 @@ homepage: http://github.com/etm/riddl/
539
539
  licenses:
540
540
  - LGPL-3.0-or-later
541
541
  metadata:
542
- documentation_uri: https://gemdocs.org/gems/riddl/1.0.12/
542
+ documentation_uri: https://gemdocs.org/gems/riddl/1.0.14/
543
543
  rdoc_options: []
544
544
  require_paths:
545
545
  - lib/ruby