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 +4 -4
- data/docs/README.md +30 -0
- data/examples/README.md +1 -0
- data/examples/multipart.rb +13 -0
- data/lib/httparty/request.rb +1 -1
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5140fa45bdc5cad9c43dedc767d225a8d303df17e7684fb229e15b5b719c7581
|
|
4
|
+
data.tar.gz: df6926136fccc436033ebdec116d46d90c9d4cc41425e064f9caa8954d174ae2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
data/examples/multipart.rb
CHANGED
|
@@ -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
|
+
)
|
data/lib/httparty/request.rb
CHANGED
|
@@ -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]
|
|
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
|
data/lib/httparty/version.rb
CHANGED
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+:]
|
|
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:
|