httparty 0.24.1 → 0.24.2

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: 1cb1b76559da322f97eb94d6f3ffb559cb724c4c7fda1cead989f28cdf723aa8
4
- data.tar.gz: 17eca4739d3c56c970c0141f1fb37dccd20112fd7fb7c5504a80db9dea89d292
3
+ metadata.gz: 5140fa45bdc5cad9c43dedc767d225a8d303df17e7684fb229e15b5b719c7581
4
+ data.tar.gz: df6926136fccc436033ebdec116d46d90c9d4cc41425e064f9caa8954d174ae2
5
5
  SHA512:
6
- metadata.gz: 5c330deb338ffa53c4da1fda045dfcc133103122dc9a4df56e82f0ff184ed49b18b3775fdc55da6117c59265db3a2f2b18c062c3ba2e3c7750fe43bb67a8ee31
7
- data.tar.gz: 4c777978ab92e2b2972fb2898ba61b153876db33a57411f775af3731978bde776a47c7cae0e4f641b3af093b781ab69644499384dba29a1e088ff59096ea1b07
6
+ metadata.gz: 0a9f6122cbddaf9929f6c0e2ecf790438b980b9c878ebb638a7ceb0f3404faf5ab722a0eeedc7d239513176a8806c5bd7963316228ab3cedc4e5a592fdea0f63
7
+ data.tar.gz: 140dd82771ccf6d1e97d427c7e60c00728e05389124a68b1dc9a6b24ef4fdbd2356dd2d1b3e7836afa17b70020fdff7f3e2a652c34eb6945cb40ef546cfa82a4
data/docs/README.md CHANGED
@@ -4,6 +4,7 @@ Makes http fun again!
4
4
 
5
5
  ## Table of contents
6
6
  - [Parsing JSON](#parsing-json)
7
+ - [File Uploads (Multipart)](#file-uploads-multipart)
7
8
  - [Working with SSL](#working-with-ssl)
8
9
 
9
10
  ## Parsing JSON
@@ -28,6 +29,35 @@ HTTParty.post('http://example.com', body: JSON.generate({ foo: 'bar' }), headers
28
29
  HTTParty.post('http://example.com', body: { foo: 'bar' }.to_json, headers: { 'Content-Type' => 'application/json' })
29
30
  ```
30
31
 
32
+ ## File Uploads (Multipart)
33
+
34
+ When you include a `File` object in the body, HTTParty automatically uses `multipart/form-data` encoding:
35
+
36
+ ```ruby
37
+ HTTParty.post('http://example.com/upload',
38
+ body: {
39
+ name: 'Foo Bar',
40
+ avatar: File.open('/path/to/avatar.jpg')
41
+ }
42
+ )
43
+ ```
44
+
45
+ ### Streaming Uploads for Large Files
46
+
47
+ For large file uploads, you can enable streaming mode to reduce memory usage. Instead of loading the entire file into memory, HTTParty will stream the file in chunks:
48
+
49
+ ```ruby
50
+ HTTParty.post('http://example.com/upload',
51
+ body: {
52
+ name: 'Foo Bar',
53
+ avatar: File.open('/path/to/large_file.zip')
54
+ },
55
+ stream_body: true
56
+ )
57
+ ```
58
+
59
+ **Note:** Some servers may not handle streaming uploads correctly. If you encounter issues (e.g., 400 errors), try without the `stream_body` option.
60
+
31
61
  ## Working with SSL
32
62
 
33
63
  You can use this guide to work with SSL certificates.
data/examples/README.md CHANGED
@@ -78,6 +78,7 @@
78
78
 
79
79
  * [Multipart](multipart.rb)
80
80
  * Multipart data upload _(with and without file)_
81
+ * Streaming uploads for large files with `stream_body: true`
81
82
 
82
83
  * [Uploading File](body_stream.rb)
83
84
  * Uses `body_stream` to upload file
@@ -20,3 +20,16 @@ HTTParty.post(
20
20
  email: 'example@email.com'
21
21
  }
22
22
  )
23
+
24
+
25
+ # For large file uploads, use stream_body: true to reduce memory usage.
26
+ # Instead of loading the entire file into memory, HTTParty will stream it in chunks.
27
+ # Note: Some servers may not handle streaming uploads correctly.
28
+
29
+ HTTParty.post(
30
+ 'http://localhost:3000/upload',
31
+ body: {
32
+ document: File.open('/full/path/to/large_file.zip')
33
+ },
34
+ stream_body: true
35
+ )
@@ -251,7 +251,7 @@ module HTTParty
251
251
  @raw_request['Content-Type'] = 'application/x-www-form-urlencoded'
252
252
  end
253
253
 
254
- if body.streaming? && options[:stream_body] != false
254
+ if body.streaming? && options[:stream_body] == true
255
255
  stream = body.to_stream
256
256
  @raw_request.body_stream = stream
257
257
  @raw_request['Content-Length'] = stream.size.to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTParty
4
- VERSION = '0.24.1'
4
+ VERSION = '0.24.2'
5
5
  end
data/lib/httparty.rb CHANGED
@@ -41,7 +41,7 @@ module HTTParty
41
41
  # [:+local_host+:] Local address to bind to before connecting.
42
42
  # [:+local_port+:] Local port to bind to before connecting.
43
43
  # [:+body_stream+:] Allow streaming to a REST server to specify a body_stream.
44
- # [:+stream_body+:] Allow for streaming large files without loading them into memory.
44
+ # [:+stream_body+:] When downloading with a block, avoids accumulating the response in memory. When uploading files, streams the request body to reduce memory usage (opt-in).
45
45
  # [:+multipart+:] Force content-type to be multipart
46
46
  #
47
47
  # There are also another set of options with names corresponding to various class methods. The methods in question are those that let you set a class-wide default, and the options override the defaults on a request-by-request basis. Those options are:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.1
4
+ version: 0.24.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker