wreq 1.2.1 → 1.2.3
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/Cargo.lock +49 -71
- data/Cargo.toml +1 -1
- data/Gemfile +1 -0
- data/README.md +7 -4
- data/build.rs +7 -0
- data/docs/windows-gnu-tokio-crash.md +70 -0
- data/lib/wreq_ruby/emulate.rb +1 -0
- data/script/build_windows_gnu.ps1 +257 -0
- data/src/arch.rs +33 -0
- data/src/client/body/stream.rs +12 -9
- data/src/client/req.rs +122 -110
- data/src/client/resp.rs +9 -17
- data/src/client.rs +21 -9
- data/src/emulate.rs +1 -0
- data/src/extractor.rs +0 -25
- data/src/header.rs +14 -0
- data/src/lib.rs +1 -0
- data/src/rt.rs +26 -9
- data/test/client_cookie_test.rb +6 -6
- data/test/client_test.rb +16 -16
- data/test/cookie_test.rb +8 -6
- data/test/error_handling_test.rb +4 -4
- data/test/header_test.rb +1 -1
- data/test/inspect_test.rb +4 -4
- data/test/module_methods_test.rb +11 -11
- data/test/request_parameters_test.rb +30 -30
- data/test/request_test.rb +22 -22
- data/test/response_test.rb +6 -6
- data/test/stream_test.rb +61 -35
- data/test/test_helper.rb +46 -3
- metadata +4 -1
data/src/client.rs
CHANGED
|
@@ -10,7 +10,7 @@ use magnus::{
|
|
|
10
10
|
Module, Object, RHash, RModule, Ruby, TryConvert, Value, function, method, typed_data::Obj,
|
|
11
11
|
};
|
|
12
12
|
use serde::Deserialize;
|
|
13
|
-
use wreq::
|
|
13
|
+
use wreq::Proxy;
|
|
14
14
|
|
|
15
15
|
use crate::{
|
|
16
16
|
client::{req::execute_request, resp::Response},
|
|
@@ -19,7 +19,7 @@ use crate::{
|
|
|
19
19
|
error::wreq_error_to_magnus,
|
|
20
20
|
extractor::Extractor,
|
|
21
21
|
gvl,
|
|
22
|
-
header::{Headers, OrigHeaders},
|
|
22
|
+
header::{Headers, OrigHeaders, UserAgent},
|
|
23
23
|
http::Method,
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -31,7 +31,7 @@ struct Builder {
|
|
|
31
31
|
emulation: Option<Emulation>,
|
|
32
32
|
/// The user agent to use for the client.
|
|
33
33
|
#[serde(skip)]
|
|
34
|
-
user_agent: Option<
|
|
34
|
+
user_agent: Option<UserAgent>,
|
|
35
35
|
/// The headers to use for the client.
|
|
36
36
|
#[serde(skip)]
|
|
37
37
|
headers: Option<Headers>,
|
|
@@ -104,6 +104,7 @@ struct Builder {
|
|
|
104
104
|
/// Bind to a local IP Address.
|
|
105
105
|
local_address: Option<IpAddr>,
|
|
106
106
|
/// Bind to an interface by `SO_BINDTODEVICE`.
|
|
107
|
+
#[allow(dead_code)]
|
|
107
108
|
interface: Option<String>,
|
|
108
109
|
|
|
109
110
|
// ========= Compression options =========
|
|
@@ -136,6 +137,10 @@ impl Builder {
|
|
|
136
137
|
builder.emulation = Some((*Obj::<Emulation>::try_convert(v)?).clone());
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
if let Some(v) = hash.get(ruby.to_symbol(stringify!(user_agent))) {
|
|
141
|
+
builder.user_agent = Some(UserAgent::try_convert(v)?);
|
|
142
|
+
}
|
|
143
|
+
|
|
139
144
|
if let Some(v) = hash.get(ruby.to_symbol(stringify!(headers))) {
|
|
140
145
|
builder.headers = Some(Headers::try_convert(v)?);
|
|
141
146
|
}
|
|
@@ -148,11 +153,6 @@ impl Builder {
|
|
|
148
153
|
builder.cookie_provider = Some((*Obj::<Jar>::try_convert(v)?).clone());
|
|
149
154
|
}
|
|
150
155
|
|
|
151
|
-
if let Some(jar) = hash.get(ruby.to_symbol(stringify!(cookie_provider))) {
|
|
152
|
-
builder.cookie_provider = Some((*Obj::<Jar>::try_convert(jar)?).clone());
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
builder.user_agent = Extractor::<HeaderValue>::try_convert(*keyword)?.into_inner();
|
|
156
156
|
builder.proxy = Extractor::<Proxy>::try_convert(*keyword)?.into_inner();
|
|
157
157
|
|
|
158
158
|
Ok(builder)
|
|
@@ -173,7 +173,7 @@ impl Client {
|
|
|
173
173
|
apply_option!(set_if_some_inner, builder, params.emulation, emulation);
|
|
174
174
|
|
|
175
175
|
// User agent options.
|
|
176
|
-
apply_option!(
|
|
176
|
+
apply_option!(set_if_some_inner, builder, params.user_agent, user_agent);
|
|
177
177
|
|
|
178
178
|
// Headers options.
|
|
179
179
|
apply_option!(
|
|
@@ -301,6 +301,18 @@ impl Client {
|
|
|
301
301
|
apply_option!(set_if_some, builder, params.proxy, proxy);
|
|
302
302
|
apply_option!(set_if_true, builder, params.no_proxy, no_proxy, false);
|
|
303
303
|
apply_option!(set_if_some, builder, params.local_address, local_address);
|
|
304
|
+
#[cfg(any(
|
|
305
|
+
target_os = "android",
|
|
306
|
+
target_os = "fuchsia",
|
|
307
|
+
target_os = "illumos",
|
|
308
|
+
target_os = "ios",
|
|
309
|
+
target_os = "linux",
|
|
310
|
+
target_os = "macos",
|
|
311
|
+
target_os = "solaris",
|
|
312
|
+
target_os = "tvos",
|
|
313
|
+
target_os = "visionos",
|
|
314
|
+
target_os = "watchos",
|
|
315
|
+
))]
|
|
304
316
|
apply_option!(set_if_some, builder, params.interface, interface);
|
|
305
317
|
|
|
306
318
|
// Compression options.
|
data/src/emulate.rs
CHANGED
data/src/extractor.rs
CHANGED
|
@@ -32,31 +32,6 @@ where
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
// ===== impl Extractor<HeaderValue> =====
|
|
36
|
-
|
|
37
|
-
impl ExtractorName for HeaderValue {
|
|
38
|
-
const NAME: &str = "user_agent";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
impl TryConvert for Extractor<HeaderValue> {
|
|
42
|
-
fn try_convert(value: magnus::Value) -> Result<Self, magnus::Error> {
|
|
43
|
-
let ruby = Ruby::get_with(value);
|
|
44
|
-
let keyword = RHash::try_convert(value)?;
|
|
45
|
-
|
|
46
|
-
if let Some(ruby_value) = keyword
|
|
47
|
-
.get(ruby.to_symbol(HeaderValue::NAME))
|
|
48
|
-
.and_then(RString::from_value)
|
|
49
|
-
{
|
|
50
|
-
return HeaderValue::from_maybe_shared(ruby_value.to_bytes())
|
|
51
|
-
.map(Some)
|
|
52
|
-
.map(Extractor)
|
|
53
|
-
.map_err(header_value_error_to_magnus);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Ok(Extractor(None))
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
35
|
// ===== impl Extractor<HeaderMap> =====
|
|
61
36
|
|
|
62
37
|
impl ExtractorName for HeaderMap {
|
data/src/header.rs
CHANGED
|
@@ -15,6 +15,9 @@ use crate::error::{
|
|
|
15
15
|
header_name_error_to_magnus, header_value_error_to_magnus, type_value_error_to_magnus,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
/// A wrapper for the User-Agent header value.
|
|
19
|
+
pub struct UserAgent(pub HeaderValue);
|
|
20
|
+
|
|
18
21
|
/// HTTP headers collection with read and write operations.
|
|
19
22
|
///
|
|
20
23
|
/// This class wraps HTTP headers and provides convenient methods for
|
|
@@ -31,6 +34,17 @@ struct HeaderIter {
|
|
|
31
34
|
next_name: Option<HeaderName>,
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
// ===== impl UserAgent =====
|
|
38
|
+
|
|
39
|
+
impl TryConvert for UserAgent {
|
|
40
|
+
fn try_convert(value: Value) -> Result<Self, Error> {
|
|
41
|
+
let s = RString::try_convert(value)?;
|
|
42
|
+
let header_value =
|
|
43
|
+
HeaderValue::from_maybe_shared(s.to_bytes()).map_err(header_value_error_to_magnus)?;
|
|
44
|
+
Ok(Self(header_value))
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
34
48
|
// ===== impl Headers =====
|
|
35
49
|
|
|
36
50
|
impl Headers {
|
data/src/lib.rs
CHANGED
data/src/rt.rs
CHANGED
|
@@ -5,25 +5,42 @@ use tokio::runtime::{Builder, Runtime};
|
|
|
5
5
|
use crate::{error::interrupt_error, gvl};
|
|
6
6
|
|
|
7
7
|
static RUNTIME: LazyLock<Runtime> = LazyLock::new(|| {
|
|
8
|
-
Builder::new_multi_thread()
|
|
8
|
+
let mut builder = Builder::new_multi_thread();
|
|
9
|
+
|
|
10
|
+
builder
|
|
9
11
|
.enable_all()
|
|
10
12
|
.build()
|
|
11
13
|
.expect("Failed to initialize Tokio runtime")
|
|
12
14
|
});
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
enum BlockOnError<E> {
|
|
17
|
+
Interrupted,
|
|
18
|
+
Future(E),
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Block on a future to completion on the global Tokio runtime.
|
|
22
|
+
///
|
|
23
|
+
/// The future runs without Ruby's GVL, so it must not construct Ruby objects or
|
|
24
|
+
/// Ruby exceptions. Convert Rust errors back into Ruby errors after the GVL has
|
|
25
|
+
/// been reacquired.
|
|
26
|
+
pub fn try_block_on<F, T, E, M>(future: F, map_err: M) -> Result<T, magnus::Error>
|
|
17
27
|
where
|
|
18
|
-
F: Future<Output = Result<T,
|
|
28
|
+
F: Future<Output = Result<T, E>>,
|
|
29
|
+
M: FnOnce(E) -> magnus::Error,
|
|
19
30
|
{
|
|
20
|
-
gvl::nogvl_cancellable(|flag| {
|
|
31
|
+
let result = gvl::nogvl_cancellable(|flag| {
|
|
21
32
|
RUNTIME.block_on(async move {
|
|
22
33
|
tokio::select! {
|
|
23
34
|
biased;
|
|
24
|
-
_ = flag.cancelled() => Err(
|
|
25
|
-
result = future => result,
|
|
35
|
+
_ = flag.cancelled() => Err(BlockOnError::Interrupted),
|
|
36
|
+
result = future => result.map_err(BlockOnError::Future),
|
|
26
37
|
}
|
|
27
38
|
})
|
|
28
|
-
})
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
match result {
|
|
42
|
+
Ok(value) => Ok(value),
|
|
43
|
+
Err(BlockOnError::Interrupted) => Err(interrupt_error()),
|
|
44
|
+
Err(BlockOnError::Future(err)) => Err(map_err(err)),
|
|
45
|
+
}
|
|
29
46
|
}
|
data/test/client_cookie_test.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require "test_helper"
|
|
4
4
|
|
|
5
5
|
class ClientCookieProviderTest < Minitest::Test
|
|
6
|
-
HOST =
|
|
6
|
+
HOST = HTTPBIN_URL
|
|
7
7
|
|
|
8
8
|
def setup
|
|
9
9
|
@jar = Wreq::Jar.new
|
|
@@ -29,9 +29,9 @@ class ClientCookieProviderTest < Minitest::Test
|
|
|
29
29
|
# subsequent request should send the stored cookie automatically
|
|
30
30
|
res2 = @client.get("#{HOST}/cookies")
|
|
31
31
|
assert_equal 200, res2.code
|
|
32
|
-
|
|
33
|
-
assert_kind_of Hash,
|
|
34
|
-
assert_equal "bar",
|
|
32
|
+
cookies = httpbin_cookies(res2.json)
|
|
33
|
+
assert_kind_of Hash, cookies
|
|
34
|
+
assert_equal "bar", httpbin_fetch(cookies, "foo")
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def test_prepopulated_jar_is_used_by_client
|
|
@@ -40,7 +40,7 @@ class ClientCookieProviderTest < Minitest::Test
|
|
|
40
40
|
|
|
41
41
|
res = @client.get("#{HOST}/cookies")
|
|
42
42
|
assert_equal 200, res.code
|
|
43
|
-
cookies = res.json
|
|
44
|
-
assert_equal "1", cookies
|
|
43
|
+
cookies = httpbin_cookies(res.json)
|
|
44
|
+
assert_equal "1", httpbin_fetch(cookies, "pref")
|
|
45
45
|
end
|
|
46
46
|
end
|
data/test/client_test.rb
CHANGED
|
@@ -20,40 +20,40 @@ class ClientTest < Minitest::Test
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def test_get_request
|
|
23
|
-
response = @client.get("
|
|
23
|
+
response = @client.get("#{HTTPBIN_URL}/get")
|
|
24
24
|
refute_nil response
|
|
25
25
|
assert_equal 200, response.code
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def test_post_request
|
|
29
|
-
response = @client.post("
|
|
29
|
+
response = @client.post("#{HTTPBIN_URL}/post",
|
|
30
30
|
json: {test: "wreq-ruby"})
|
|
31
31
|
refute_nil response
|
|
32
32
|
assert_equal 200, response.code
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def test_put_request
|
|
36
|
-
response = @client.put("
|
|
36
|
+
response = @client.put("#{HTTPBIN_URL}/put",
|
|
37
37
|
json: {data: "test"})
|
|
38
38
|
refute_nil response
|
|
39
39
|
assert_equal 200, response.code
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def test_delete_request
|
|
43
|
-
response = @client.delete("
|
|
43
|
+
response = @client.delete("#{HTTPBIN_URL}/delete")
|
|
44
44
|
refute_nil response
|
|
45
45
|
assert_equal 200, response.code
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def test_patch_request
|
|
49
|
-
response = @client.patch("
|
|
49
|
+
response = @client.patch("#{HTTPBIN_URL}/patch",
|
|
50
50
|
json: {update: "field"})
|
|
51
51
|
refute_nil response
|
|
52
52
|
assert_equal 200, response.code
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def test_request_with_query_params
|
|
56
|
-
response = @client.get("
|
|
56
|
+
response = @client.get("#{HTTPBIN_URL}/get",
|
|
57
57
|
query: {"param" => "value"})
|
|
58
58
|
refute_nil response
|
|
59
59
|
assert_equal 200, response.code
|
|
@@ -61,7 +61,7 @@ class ClientTest < Minitest::Test
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def test_request_with_form_data
|
|
64
|
-
response = @client.post("
|
|
64
|
+
response = @client.post("#{HTTPBIN_URL}/post",
|
|
65
65
|
form: {"field" => "value"})
|
|
66
66
|
refute_nil response
|
|
67
67
|
assert_equal 200, response.code
|
|
@@ -69,7 +69,7 @@ class ClientTest < Minitest::Test
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def test_request_with_raw_body
|
|
72
|
-
response = @client.post("
|
|
72
|
+
response = @client.post("#{HTTPBIN_URL}/post",
|
|
73
73
|
body: "raw content",
|
|
74
74
|
headers: {"Content-Type" => "text/plain"})
|
|
75
75
|
refute_nil response
|
|
@@ -78,14 +78,14 @@ class ClientTest < Minitest::Test
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def test_basic_authentication
|
|
81
|
-
response = @client.get("
|
|
81
|
+
response = @client.get("#{HTTPBIN_URL}/basic-auth/user/pass",
|
|
82
82
|
basic_auth: ["user", "pass"])
|
|
83
83
|
refute_nil response
|
|
84
84
|
assert_equal 200, response.code
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def test_bearer_authentication
|
|
88
|
-
response = @client.get("
|
|
88
|
+
response = @client.get("#{HTTPBIN_URL}/bearer",
|
|
89
89
|
bearer_auth: "test-token")
|
|
90
90
|
refute_nil response
|
|
91
91
|
assert_equal 200, response.code
|
|
@@ -93,21 +93,21 @@ class ClientTest < Minitest::Test
|
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def test_redirect_following
|
|
96
|
-
response = @client.get("
|
|
96
|
+
response = @client.get("#{HTTPBIN_URL}/redirect/1",
|
|
97
97
|
allow_redirects: true)
|
|
98
98
|
refute_nil response
|
|
99
99
|
assert_equal 200, response.code
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def test_redirect_blocking
|
|
103
|
-
response = @client.get("
|
|
103
|
+
response = @client.get("#{HTTPBIN_URL}/redirect/1",
|
|
104
104
|
allow_redirects: false)
|
|
105
105
|
refute_nil response
|
|
106
106
|
assert_equal 302, response.code
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
def test_gzip_compression
|
|
110
|
-
response = @client.get("
|
|
110
|
+
response = @client.get("#{HTTPBIN_URL}/gzip", gzip: true)
|
|
111
111
|
refute_nil response
|
|
112
112
|
assert_equal 200, response.code
|
|
113
113
|
end
|
|
@@ -115,12 +115,12 @@ class ClientTest < Minitest::Test
|
|
|
115
115
|
def test_timeout_handling
|
|
116
116
|
# Test that short timeouts properly raise exceptions
|
|
117
117
|
assert_raises(Wreq::TimeoutError) do
|
|
118
|
-
@client.get("
|
|
118
|
+
@client.get("#{HTTPBIN_URL}/delay/10", timeout: 1)
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
# Test that reasonable timeouts work normally
|
|
122
122
|
start_time = Time.now
|
|
123
|
-
response = @client.get("
|
|
123
|
+
response = @client.get("#{HTTPBIN_URL}/delay/1", timeout: 5)
|
|
124
124
|
elapsed = Time.now - start_time
|
|
125
125
|
|
|
126
126
|
refute_nil response
|
|
@@ -129,7 +129,7 @@ class ClientTest < Minitest::Test
|
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
def test_status_codes
|
|
132
|
-
response = @client.get("
|
|
132
|
+
response = @client.get("#{HTTPBIN_URL}/status/404")
|
|
133
133
|
refute_nil response
|
|
134
134
|
assert_equal 404, response.code
|
|
135
135
|
end
|
data/test/cookie_test.rb
CHANGED
|
@@ -157,24 +157,26 @@ class CookieTest < Minitest::Test
|
|
|
157
157
|
def test_request_uncompressed_cookies
|
|
158
158
|
client = Wreq::Client.new
|
|
159
159
|
resp = client.get(
|
|
160
|
-
"
|
|
160
|
+
"#{HTTPBIN_URL}/cookies",
|
|
161
161
|
cookies: {"foo" => "bar", "baz" => "qux"}
|
|
162
162
|
)
|
|
163
163
|
json = resp.json
|
|
164
164
|
assert_instance_of Hash, json
|
|
165
|
-
|
|
166
|
-
assert_equal "
|
|
165
|
+
cookies = json.fetch("cookies", json)
|
|
166
|
+
assert_equal "bar", cookies["foo"]
|
|
167
|
+
assert_equal "qux", cookies["baz"]
|
|
167
168
|
end
|
|
168
169
|
|
|
169
170
|
def test_request_compressed_cookies
|
|
170
171
|
client = Wreq::Client.new
|
|
171
172
|
resp = client.get(
|
|
172
|
-
"
|
|
173
|
+
"#{HTTPBIN_URL}/cookies",
|
|
173
174
|
cookies: "foo=bar; baz=qux"
|
|
174
175
|
)
|
|
175
176
|
json = resp.json
|
|
176
177
|
assert_instance_of Hash, json
|
|
177
|
-
|
|
178
|
-
assert_equal "
|
|
178
|
+
cookies = json.fetch("cookies", json)
|
|
179
|
+
assert_equal "bar", cookies["foo"]
|
|
180
|
+
assert_equal "qux", cookies["baz"]
|
|
179
181
|
end
|
|
180
182
|
end
|
data/test/error_handling_test.rb
CHANGED
|
@@ -21,7 +21,7 @@ class ErrorHandlingTest < Minitest::Test
|
|
|
21
21
|
def test_http_error_status_codes
|
|
22
22
|
# These should not raise errors, just return responses with error codes
|
|
23
23
|
[400, 401, 403, 404, 500, 502, 503].each do |status_code|
|
|
24
|
-
response = Wreq.get("
|
|
24
|
+
response = Wreq.get("#{HTTPBIN_URL}/status/#{status_code}")
|
|
25
25
|
assert_equal status_code, response.code
|
|
26
26
|
# Should not raise an exception for HTTP error codes
|
|
27
27
|
end
|
|
@@ -31,7 +31,7 @@ class ErrorHandlingTest < Minitest::Test
|
|
|
31
31
|
# Test timeout with a delay that should definitely cause timeout
|
|
32
32
|
|
|
33
33
|
# Request with a very short timeout that should fail
|
|
34
|
-
response = Wreq.get("
|
|
34
|
+
response = Wreq.get("#{HTTPBIN_URL}/delay/10", timeout: 1)
|
|
35
35
|
# If we get here, the request didn't timeout (unexpected)
|
|
36
36
|
flunk "Expected timeout error but got response: #{response.code}"
|
|
37
37
|
rescue => e
|
|
@@ -42,7 +42,7 @@ class ErrorHandlingTest < Minitest::Test
|
|
|
42
42
|
|
|
43
43
|
def test_invalid_json_response
|
|
44
44
|
# Get a non-JSON response and try to parse as JSON
|
|
45
|
-
response = Wreq.get("
|
|
45
|
+
response = Wreq.get("#{HTTPBIN_URL}/html")
|
|
46
46
|
assert_equal 200, response.code
|
|
47
47
|
|
|
48
48
|
# Should raise an error when trying to parse HTML as JSON
|
|
@@ -54,7 +54,7 @@ class ErrorHandlingTest < Minitest::Test
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def test_empty_response_json
|
|
57
|
-
response = Wreq.get("
|
|
57
|
+
response = Wreq.get("#{HTTPBIN_URL}/status/204")
|
|
58
58
|
assert_equal 204, response.code
|
|
59
59
|
assert_equal "", response.text
|
|
60
60
|
|
data/test/header_test.rb
CHANGED
|
@@ -2,7 +2,7 @@ require "test_helper"
|
|
|
2
2
|
|
|
3
3
|
class HeadersTest < Minitest::Test
|
|
4
4
|
def setup
|
|
5
|
-
@response = Wreq.get("
|
|
5
|
+
@response = Wreq.get("#{HTTPBIN_URL}/response-headers",
|
|
6
6
|
query: {
|
|
7
7
|
"X-Custom-Header" => "custom-value",
|
|
8
8
|
"X-Multi-Header" => "value1"
|
data/test/inspect_test.rb
CHANGED
|
@@ -84,12 +84,12 @@ class InspectTest < Minitest::Test
|
|
|
84
84
|
# ---- Response ----
|
|
85
85
|
|
|
86
86
|
def test_response_to_s_returns_body
|
|
87
|
-
response = Wreq.get("
|
|
87
|
+
response = Wreq.get("#{HTTPBIN_URL}/json")
|
|
88
88
|
assert_equal response.text, response.to_s
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def test_response_inspect_format
|
|
92
|
-
response = Wreq.get("
|
|
92
|
+
response = Wreq.get("#{HTTPBIN_URL}/json")
|
|
93
93
|
result = response.inspect
|
|
94
94
|
assert result.start_with?("#<Wreq::Response")
|
|
95
95
|
assert_includes result, "200"
|
|
@@ -99,7 +99,7 @@ class InspectTest < Minitest::Test
|
|
|
99
99
|
# ---- StatusCode ----
|
|
100
100
|
|
|
101
101
|
def test_status_code_inspect
|
|
102
|
-
response = Wreq.get("
|
|
102
|
+
response = Wreq.get("#{HTTPBIN_URL}/status/200")
|
|
103
103
|
result = response.status.inspect
|
|
104
104
|
assert result.start_with?("#<Wreq::StatusCode")
|
|
105
105
|
assert_includes result, response.status.to_s
|
|
@@ -117,7 +117,7 @@ class InspectTest < Minitest::Test
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
def test_version_inspect_from_response
|
|
120
|
-
response = Wreq.get("
|
|
120
|
+
response = Wreq.get("#{HTTPBIN_URL}/get")
|
|
121
121
|
result = response.version.inspect
|
|
122
122
|
assert result.start_with?("#<Wreq::Version")
|
|
123
123
|
assert result.end_with?(">")
|
data/test/module_methods_test.rb
CHANGED
|
@@ -2,33 +2,33 @@ require "test_helper"
|
|
|
2
2
|
|
|
3
3
|
class ModuleMethodsTest < Minitest::Test
|
|
4
4
|
def test_module_get
|
|
5
|
-
response = Wreq.get("
|
|
5
|
+
response = Wreq.get("#{HTTPBIN_URL}/get")
|
|
6
6
|
refute_nil response
|
|
7
7
|
assert_equal 200, response.code
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def test_module_post
|
|
11
|
-
response = Wreq.post("
|
|
11
|
+
response = Wreq.post("#{HTTPBIN_URL}/post",
|
|
12
12
|
json: {module: "test"})
|
|
13
13
|
refute_nil response
|
|
14
14
|
assert_equal 200, response.code
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def test_module_put
|
|
18
|
-
response = Wreq.put("
|
|
18
|
+
response = Wreq.put("#{HTTPBIN_URL}/put",
|
|
19
19
|
json: {data: "test"})
|
|
20
20
|
refute_nil response
|
|
21
21
|
assert_equal 200, response.code
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def test_module_delete
|
|
25
|
-
response = Wreq.delete("
|
|
25
|
+
response = Wreq.delete("#{HTTPBIN_URL}/delete")
|
|
26
26
|
refute_nil response
|
|
27
27
|
assert_equal 200, response.code
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def test_module_patch
|
|
31
|
-
response = Wreq.patch("
|
|
31
|
+
response = Wreq.patch("#{HTTPBIN_URL}/patch",
|
|
32
32
|
json: {update: "field"})
|
|
33
33
|
refute_nil response
|
|
34
34
|
assert_equal 200, response.code
|
|
@@ -37,23 +37,23 @@ class ModuleMethodsTest < Minitest::Test
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def test_module_request_method
|
|
40
|
-
response = Wreq.request(Wreq::Method::GET, "
|
|
40
|
+
response = Wreq.request(Wreq::Method::GET, "#{HTTPBIN_URL}/get")
|
|
41
41
|
refute_nil response
|
|
42
42
|
assert_equal 200, response.code
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def test_module_methods_with_parameters
|
|
46
|
-
response = Wreq.get("
|
|
46
|
+
response = Wreq.get("#{HTTPBIN_URL}/get",
|
|
47
47
|
headers: {"Accept" => "application/json"},
|
|
48
48
|
query: {"test" => "module"})
|
|
49
49
|
refute_nil response
|
|
50
|
-
assert_equal
|
|
51
|
-
|
|
50
|
+
assert_equal "#{HTTPBIN_URL}/get?test=module", response.url
|
|
51
|
+
assert_equal "module", httpbin_fetch(response.json["args"], "test")
|
|
52
52
|
assert_equal 200, response.code
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def test_module_post_with_json
|
|
56
|
-
response = Wreq.post("
|
|
56
|
+
response = Wreq.post("#{HTTPBIN_URL}/post",
|
|
57
57
|
json: {
|
|
58
58
|
string: "test",
|
|
59
59
|
number: 123,
|
|
@@ -65,7 +65,7 @@ class ModuleMethodsTest < Minitest::Test
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def test_module_post_with_form
|
|
68
|
-
response = Wreq.post("
|
|
68
|
+
response = Wreq.post("#{HTTPBIN_URL}/post",
|
|
69
69
|
form: {"field1" => "value1", "field2" => "value2"})
|
|
70
70
|
refute_nil response
|
|
71
71
|
assert_equal 200, response.code
|