httpx 0.20.0 → 1.3.1

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.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +0 -48
  3. data/README.md +54 -45
  4. data/doc/release_notes/0_10_0.md +2 -2
  5. data/doc/release_notes/0_11_0.md +3 -5
  6. data/doc/release_notes/0_12_0.md +5 -5
  7. data/doc/release_notes/0_13_0.md +5 -5
  8. data/doc/release_notes/0_14_0.md +2 -2
  9. data/doc/release_notes/0_16_0.md +3 -3
  10. data/doc/release_notes/0_17_0.md +1 -1
  11. data/doc/release_notes/0_18_0.md +4 -4
  12. data/doc/release_notes/0_18_2.md +1 -1
  13. data/doc/release_notes/0_19_0.md +1 -1
  14. data/doc/release_notes/0_19_8.md +1 -1
  15. data/doc/release_notes/0_20_0.md +2 -2
  16. data/doc/release_notes/0_20_1.md +5 -0
  17. data/doc/release_notes/0_20_2.md +7 -0
  18. data/doc/release_notes/0_20_3.md +6 -0
  19. data/doc/release_notes/0_20_4.md +17 -0
  20. data/doc/release_notes/0_20_5.md +3 -0
  21. data/doc/release_notes/0_21_0.md +96 -0
  22. data/doc/release_notes/0_21_1.md +12 -0
  23. data/doc/release_notes/0_22_0.md +13 -0
  24. data/doc/release_notes/0_22_1.md +11 -0
  25. data/doc/release_notes/0_22_2.md +5 -0
  26. data/doc/release_notes/0_22_3.md +55 -0
  27. data/doc/release_notes/0_22_4.md +6 -0
  28. data/doc/release_notes/0_22_5.md +6 -0
  29. data/doc/release_notes/0_23_0.md +42 -0
  30. data/doc/release_notes/0_23_1.md +5 -0
  31. data/doc/release_notes/0_23_2.md +5 -0
  32. data/doc/release_notes/0_23_3.md +6 -0
  33. data/doc/release_notes/0_23_4.md +5 -0
  34. data/doc/release_notes/0_24_0.md +48 -0
  35. data/doc/release_notes/0_24_1.md +12 -0
  36. data/doc/release_notes/0_24_2.md +12 -0
  37. data/doc/release_notes/0_24_3.md +12 -0
  38. data/doc/release_notes/0_24_4.md +18 -0
  39. data/doc/release_notes/0_24_5.md +6 -0
  40. data/doc/release_notes/0_24_6.md +5 -0
  41. data/doc/release_notes/0_24_7.md +10 -0
  42. data/doc/release_notes/1_0_0.md +60 -0
  43. data/doc/release_notes/1_0_1.md +5 -0
  44. data/doc/release_notes/1_0_2.md +7 -0
  45. data/doc/release_notes/1_1_0.md +32 -0
  46. data/doc/release_notes/1_1_1.md +17 -0
  47. data/doc/release_notes/1_1_2.md +12 -0
  48. data/doc/release_notes/1_1_3.md +18 -0
  49. data/doc/release_notes/1_1_4.md +6 -0
  50. data/doc/release_notes/1_1_5.md +12 -0
  51. data/doc/release_notes/1_2_0.md +49 -0
  52. data/doc/release_notes/1_2_1.md +6 -0
  53. data/doc/release_notes/1_2_2.md +10 -0
  54. data/doc/release_notes/1_2_3.md +16 -0
  55. data/doc/release_notes/1_2_4.md +8 -0
  56. data/doc/release_notes/1_2_5.md +7 -0
  57. data/doc/release_notes/1_2_6.md +13 -0
  58. data/doc/release_notes/1_3_0.md +18 -0
  59. data/doc/release_notes/1_3_1.md +17 -0
  60. data/lib/httpx/adapters/datadog.rb +215 -122
  61. data/lib/httpx/adapters/faraday.rb +145 -107
  62. data/lib/httpx/adapters/sentry.rb +26 -7
  63. data/lib/httpx/adapters/webmock.rb +34 -18
  64. data/lib/httpx/altsvc.rb +63 -26
  65. data/lib/httpx/base64.rb +27 -0
  66. data/lib/httpx/buffer.rb +12 -0
  67. data/lib/httpx/callbacks.rb +5 -3
  68. data/lib/httpx/chainable.rb +54 -39
  69. data/lib/httpx/connection/http1.rb +75 -44
  70. data/lib/httpx/connection/http2.rb +31 -38
  71. data/lib/httpx/connection.rb +287 -117
  72. data/lib/httpx/domain_name.rb +10 -13
  73. data/lib/httpx/errors.rb +52 -2
  74. data/lib/httpx/extensions.rb +24 -131
  75. data/lib/httpx/io/ssl.rb +83 -77
  76. data/lib/httpx/io/tcp.rb +48 -71
  77. data/lib/httpx/io/udp.rb +18 -52
  78. data/lib/httpx/io/unix.rb +10 -15
  79. data/lib/httpx/io.rb +3 -9
  80. data/lib/httpx/loggable.rb +4 -19
  81. data/lib/httpx/options.rb +176 -118
  82. data/lib/httpx/parser/http1.rb +4 -0
  83. data/lib/httpx/plugins/{authentication → auth}/basic.rb +1 -5
  84. data/lib/httpx/plugins/{authentication → auth}/digest.rb +14 -14
  85. data/lib/httpx/plugins/{authentication → auth}/ntlm.rb +1 -3
  86. data/lib/httpx/plugins/{authentication → auth}/socks5.rb +0 -2
  87. data/lib/httpx/plugins/auth.rb +25 -0
  88. data/lib/httpx/plugins/aws_sdk_authentication.rb +4 -3
  89. data/lib/httpx/plugins/aws_sigv4.rb +12 -9
  90. data/lib/httpx/plugins/basic_auth.rb +29 -0
  91. data/lib/httpx/plugins/brotli.rb +50 -0
  92. data/lib/httpx/plugins/callbacks.rb +91 -0
  93. data/lib/httpx/plugins/circuit_breaker/circuit.rb +100 -0
  94. data/lib/httpx/plugins/circuit_breaker/circuit_store.rb +53 -0
  95. data/lib/httpx/plugins/circuit_breaker.rb +148 -0
  96. data/lib/httpx/plugins/cookies/set_cookie_parser.rb +0 -2
  97. data/lib/httpx/plugins/cookies.rb +30 -17
  98. data/lib/httpx/plugins/{digest_authentication.rb → digest_auth.rb} +14 -12
  99. data/lib/httpx/plugins/expect.rb +21 -14
  100. data/lib/httpx/plugins/follow_redirects.rb +140 -41
  101. data/lib/httpx/plugins/grpc/call.rb +2 -3
  102. data/lib/httpx/plugins/grpc/grpc_encoding.rb +88 -0
  103. data/lib/httpx/plugins/grpc/message.rb +7 -37
  104. data/lib/httpx/plugins/grpc.rb +36 -29
  105. data/lib/httpx/plugins/h2c.rb +26 -19
  106. data/lib/httpx/plugins/internal_telemetry.rb +16 -0
  107. data/lib/httpx/plugins/{ntlm_authentication.rb → ntlm_auth.rb} +7 -5
  108. data/lib/httpx/plugins/oauth.rb +175 -0
  109. data/lib/httpx/plugins/persistent.rb +1 -1
  110. data/lib/httpx/plugins/proxy/http.rb +23 -13
  111. data/lib/httpx/plugins/proxy/socks4.rb +9 -7
  112. data/lib/httpx/plugins/proxy/socks5.rb +11 -9
  113. data/lib/httpx/plugins/proxy.rb +80 -61
  114. data/lib/httpx/plugins/push_promise.rb +1 -1
  115. data/lib/httpx/plugins/rate_limiter.rb +5 -1
  116. data/lib/httpx/plugins/response_cache/file_store.rb +40 -0
  117. data/lib/httpx/plugins/response_cache/store.rb +62 -25
  118. data/lib/httpx/plugins/response_cache.rb +105 -12
  119. data/lib/httpx/plugins/retries.rb +87 -17
  120. data/lib/httpx/plugins/ssrf_filter.rb +145 -0
  121. data/lib/httpx/plugins/stream.rb +27 -23
  122. data/lib/httpx/plugins/upgrade/h2.rb +4 -4
  123. data/lib/httpx/plugins/upgrade.rb +8 -10
  124. data/lib/httpx/plugins/webdav.rb +80 -0
  125. data/lib/httpx/pool/synch_pool.rb +93 -0
  126. data/lib/httpx/pool.rb +102 -27
  127. data/lib/httpx/punycode.rb +9 -291
  128. data/lib/httpx/request/body.rb +154 -0
  129. data/lib/httpx/request.rb +130 -146
  130. data/lib/httpx/resolver/https.rb +62 -27
  131. data/lib/httpx/resolver/multi.rb +9 -13
  132. data/lib/httpx/resolver/native.rb +192 -76
  133. data/lib/httpx/resolver/resolver.rb +34 -9
  134. data/lib/httpx/resolver/system.rb +16 -11
  135. data/lib/httpx/resolver.rb +38 -16
  136. data/lib/httpx/response/body.rb +242 -0
  137. data/lib/httpx/response/buffer.rb +96 -0
  138. data/lib/httpx/response.rb +159 -217
  139. data/lib/httpx/selector.rb +9 -4
  140. data/lib/httpx/session.rb +137 -89
  141. data/lib/httpx/session_extensions.rb +4 -1
  142. data/lib/httpx/timers.rb +34 -8
  143. data/lib/httpx/transcoder/body.rb +0 -2
  144. data/lib/httpx/transcoder/chunker.rb +0 -1
  145. data/lib/httpx/transcoder/deflate.rb +37 -0
  146. data/lib/httpx/transcoder/form.rb +52 -33
  147. data/lib/httpx/transcoder/gzip.rb +74 -0
  148. data/lib/httpx/transcoder/json.rb +21 -8
  149. data/lib/httpx/transcoder/multipart/decoder.rb +139 -0
  150. data/lib/httpx/{plugins → transcoder}/multipart/encoder.rb +4 -4
  151. data/lib/httpx/{plugins → transcoder}/multipart/mime_type_detector.rb +1 -1
  152. data/lib/httpx/{plugins → transcoder}/multipart/part.rb +3 -2
  153. data/lib/httpx/transcoder/multipart.rb +17 -0
  154. data/lib/httpx/transcoder/utils/body_reader.rb +46 -0
  155. data/lib/httpx/transcoder/utils/deflater.rb +72 -0
  156. data/lib/httpx/transcoder/utils/inflater.rb +19 -0
  157. data/lib/httpx/transcoder/xml.rb +52 -0
  158. data/lib/httpx/transcoder.rb +5 -6
  159. data/lib/httpx/utils.rb +36 -16
  160. data/lib/httpx/version.rb +1 -1
  161. data/lib/httpx.rb +12 -14
  162. data/sig/altsvc.rbs +33 -0
  163. data/sig/buffer.rbs +2 -1
  164. data/sig/callbacks.rbs +3 -3
  165. data/sig/chainable.rbs +11 -9
  166. data/sig/connection/http1.rbs +8 -7
  167. data/sig/connection/http2.rbs +19 -19
  168. data/sig/connection.rbs +64 -24
  169. data/sig/errors.rbs +22 -3
  170. data/sig/httpx.rbs +5 -4
  171. data/sig/io/ssl.rbs +27 -0
  172. data/sig/io/tcp.rbs +60 -0
  173. data/sig/io/udp.rbs +20 -0
  174. data/sig/io/unix.rbs +27 -0
  175. data/sig/io.rbs +6 -0
  176. data/sig/options.rbs +32 -22
  177. data/sig/parser/http1.rbs +1 -1
  178. data/sig/plugins/{authentication → auth}/basic.rbs +0 -2
  179. data/sig/plugins/{authentication → auth}/digest.rbs +2 -1
  180. data/sig/plugins/auth.rbs +13 -0
  181. data/sig/plugins/{basic_authentication.rbs → basic_auth.rbs} +2 -2
  182. data/sig/plugins/brotli.rbs +22 -0
  183. data/sig/plugins/callbacks.rbs +38 -0
  184. data/sig/plugins/circuit_breaker.rbs +71 -0
  185. data/sig/plugins/compression.rbs +7 -5
  186. data/sig/plugins/cookies/jar.rbs +2 -2
  187. data/sig/plugins/cookies.rbs +2 -0
  188. data/sig/plugins/{digest_authentication.rbs → digest_auth.rbs} +2 -2
  189. data/sig/plugins/follow_redirects.rbs +18 -4
  190. data/sig/plugins/grpc/call.rbs +19 -0
  191. data/sig/plugins/grpc/grpc_encoding.rbs +37 -0
  192. data/sig/plugins/grpc/message.rbs +17 -0
  193. data/sig/plugins/grpc.rbs +7 -32
  194. data/sig/plugins/h2c.rbs +1 -1
  195. data/sig/plugins/{ntlm_authentication.rbs → ntlm_auth.rbs} +2 -2
  196. data/sig/plugins/oauth.rbs +54 -0
  197. data/sig/plugins/proxy/http.rbs +3 -0
  198. data/sig/plugins/proxy/socks4.rbs +9 -6
  199. data/sig/plugins/proxy/socks5.rbs +10 -6
  200. data/sig/plugins/proxy/ssh.rbs +1 -1
  201. data/sig/plugins/proxy.rbs +13 -5
  202. data/sig/plugins/push_promise.rbs +3 -3
  203. data/sig/plugins/rate_limiter.rbs +1 -1
  204. data/sig/plugins/response_cache.rbs +36 -7
  205. data/sig/plugins/retries.rbs +30 -8
  206. data/sig/plugins/stream.rbs +24 -17
  207. data/sig/plugins/upgrade.rbs +5 -3
  208. data/sig/pool.rbs +10 -7
  209. data/sig/request/body.rbs +38 -0
  210. data/sig/request.rbs +15 -24
  211. data/sig/resolver/https.rbs +8 -3
  212. data/sig/resolver/native.rbs +17 -4
  213. data/sig/resolver/resolver.rbs +8 -6
  214. data/sig/resolver/system.rbs +2 -0
  215. data/sig/resolver.rbs +9 -5
  216. data/sig/response/body.rbs +53 -0
  217. data/sig/response/buffer.rbs +24 -0
  218. data/sig/response.rbs +24 -39
  219. data/sig/selector.rbs +1 -1
  220. data/sig/session.rbs +29 -18
  221. data/sig/timers.rbs +18 -8
  222. data/sig/transcoder/body.rbs +4 -3
  223. data/sig/transcoder/deflate.rbs +11 -0
  224. data/sig/transcoder/form.rbs +5 -3
  225. data/sig/transcoder/gzip.rbs +24 -0
  226. data/sig/transcoder/json.rbs +8 -3
  227. data/sig/{plugins → transcoder}/multipart.rbs +15 -19
  228. data/sig/transcoder/utils/body_reader.rbs +15 -0
  229. data/sig/transcoder/utils/deflater.rbs +29 -0
  230. data/sig/transcoder/utils/inflater.rbs +12 -0
  231. data/sig/transcoder/xml.rbs +22 -0
  232. data/sig/transcoder.rbs +24 -9
  233. data/sig/utils.rbs +8 -2
  234. metadata +163 -41
  235. data/lib/httpx/plugins/authentication.rb +0 -20
  236. data/lib/httpx/plugins/basic_authentication.rb +0 -30
  237. data/lib/httpx/plugins/compression/brotli.rb +0 -54
  238. data/lib/httpx/plugins/compression/deflate.rb +0 -49
  239. data/lib/httpx/plugins/compression/gzip.rb +0 -88
  240. data/lib/httpx/plugins/compression.rb +0 -164
  241. data/lib/httpx/plugins/multipart/decoder.rb +0 -187
  242. data/lib/httpx/plugins/multipart.rb +0 -84
  243. data/lib/httpx/registry.rb +0 -85
  244. data/sig/plugins/authentication.rbs +0 -11
  245. data/sig/plugins/compression/brotli.rbs +0 -21
  246. data/sig/plugins/compression/deflate.rbs +0 -17
  247. data/sig/plugins/compression/gzip.rbs +0 -29
  248. data/sig/registry.rbs +0 -12
  249. /data/sig/plugins/{authentication → auth}/ntlm.rbs +0 -0
  250. /data/sig/plugins/{authentication → auth}/socks5.rbs +0 -0
data/lib/httpx/io/tcp.rb CHANGED
@@ -17,7 +17,7 @@ module HTTPX
17
17
  @state = :idle
18
18
  @addresses = []
19
19
  @hostname = origin.host
20
- @options = Options.new(options)
20
+ @options = options
21
21
  @fallback_protocol = @options.fallback_protocol
22
22
  @port = origin.port
23
23
  @interests = :w
@@ -38,7 +38,10 @@ module HTTPX
38
38
  add_addresses(addresses)
39
39
  end
40
40
  @ip_index = @addresses.size - 1
41
- # @io ||= build_socket
41
+ end
42
+
43
+ def socket
44
+ @io
42
45
  end
43
46
 
44
47
  def add_addresses(addrs)
@@ -74,7 +77,9 @@ module HTTPX
74
77
  try_connect
75
78
  rescue Errno::ECONNREFUSED,
76
79
  Errno::EADDRNOTAVAIL,
77
- Errno::EHOSTUNREACH => e
80
+ Errno::EHOSTUNREACH,
81
+ SocketError,
82
+ IOError => e
78
83
  raise e if @ip_index <= 0
79
84
 
80
85
  log { "failed connecting to #{@ip} (#{e.message}), trying next..." }
@@ -90,84 +95,45 @@ module HTTPX
90
95
  retry
91
96
  end
92
97
 
93
- if RUBY_VERSION < "2.3"
94
- # :nocov:
95
- def try_connect
96
- @io.connect_nonblock(Socket.sockaddr_in(@port, @ip.to_s))
97
- rescue ::IO::WaitWritable, Errno::EALREADY
98
- @interests = :w
99
- rescue ::IO::WaitReadable
98
+ def try_connect
99
+ ret = @io.connect_nonblock(Socket.sockaddr_in(@port, @ip.to_s), exception: false)
100
+ log(level: 3, color: :cyan) { "TCP CONNECT: #{ret}..." }
101
+ case ret
102
+ when :wait_readable
100
103
  @interests = :r
101
- rescue Errno::EISCONN
102
- transition(:connected)
103
- @interests = :w
104
- else
105
- transition(:connected)
104
+ return
105
+ when :wait_writable
106
106
  @interests = :w
107
+ return
107
108
  end
108
- private :try_connect
109
+ transition(:connected)
110
+ @interests = :w
111
+ rescue Errno::EALREADY
112
+ @interests = :w
113
+ end
114
+ private :try_connect
109
115
 
110
- def read(size, buffer)
111
- @io.read_nonblock(size, buffer)
112
- log { "READ: #{buffer.bytesize} bytes..." }
113
- buffer.bytesize
114
- rescue ::IO::WaitReadable
116
+ def read(size, buffer)
117
+ ret = @io.read_nonblock(size, buffer, exception: false)
118
+ if ret == :wait_readable
115
119
  buffer.clear
116
- 0
117
- rescue EOFError
118
- nil
119
- end
120
-
121
- def write(buffer)
122
- siz = @io.write_nonblock(buffer)
123
- log { "WRITE: #{siz} bytes..." }
124
- buffer.shift!(siz)
125
- siz
126
- rescue ::IO::WaitWritable
127
- 0
128
- rescue EOFError
129
- nil
130
- end
131
- # :nocov:
132
- else
133
- def try_connect
134
- case @io.connect_nonblock(Socket.sockaddr_in(@port, @ip.to_s), exception: false)
135
- when :wait_readable
136
- @interests = :r
137
- return
138
- when :wait_writable
139
- @interests = :w
140
- return
141
- end
142
- transition(:connected)
143
- @interests = :w
144
- rescue Errno::EALREADY
145
- @interests = :w
120
+ return 0
146
121
  end
147
- private :try_connect
148
-
149
- def read(size, buffer)
150
- ret = @io.read_nonblock(size, buffer, exception: false)
151
- if ret == :wait_readable
152
- buffer.clear
153
- return 0
154
- end
155
- return if ret.nil?
122
+ return if ret.nil?
156
123
 
157
- log { "READ: #{buffer.bytesize} bytes..." }
158
- buffer.bytesize
159
- end
124
+ log { "READ: #{buffer.bytesize} bytes..." }
125
+ buffer.bytesize
126
+ end
160
127
 
161
- def write(buffer)
162
- siz = @io.write_nonblock(buffer, exception: false)
163
- return 0 if siz == :wait_writable
164
- return if siz.nil?
128
+ def write(buffer)
129
+ siz = @io.write_nonblock(buffer, exception: false)
130
+ return 0 if siz == :wait_writable
131
+ return if siz.nil?
165
132
 
166
- log { "WRITE: #{siz} bytes..." }
133
+ log { "WRITE: #{siz} bytes..." }
167
134
 
168
- buffer.shift!(siz)
169
- siz
170
- end
135
+ buffer.shift!(siz)
136
+ siz
171
137
  end
172
138
 
173
139
  def close
@@ -188,6 +154,17 @@ module HTTPX
188
154
  @state == :idle || @state == :closed
189
155
  end
190
156
 
157
+ def expired?
158
+ # do not mess with external sockets
159
+ return false if @options.io
160
+
161
+ return true unless @addresses
162
+
163
+ resolver_addresses = Resolver.nolookup_resolve(@hostname)
164
+
165
+ (Array(resolver_addresses) & @addresses).empty?
166
+ end
167
+
191
168
  # :nocov:
192
169
  def inspect
193
170
  "#<#{self.class}: #{@ip}:#{@port} (state: #{@state})>"
data/lib/httpx/io/udp.rb CHANGED
@@ -6,11 +6,10 @@ module HTTPX
6
6
  class UDP
7
7
  include Loggable
8
8
 
9
- def initialize(uri, _, options)
10
- ip = IPAddr.new(uri.host)
11
- @host = ip.to_s
12
- @port = uri.port
13
- @io = UDPSocket.new(ip.family)
9
+ def initialize(ip, port, options)
10
+ @host = ip
11
+ @port = port
12
+ @io = UDPSocket.new(IPAddr.new(ip).family)
14
13
  @options = options
15
14
  end
16
15
 
@@ -24,45 +23,19 @@ module HTTPX
24
23
  true
25
24
  end
26
25
 
27
- if RUBY_VERSION < "2.3"
28
- # :nocov:
29
- def close
30
- @io.close
31
- rescue StandardError
32
- nil
33
- end
34
- # :nocov:
35
- else
36
- def close
37
- @io.close
38
- end
26
+ def close
27
+ @io.close
39
28
  end
40
29
 
41
- # :nocov:
42
- if (RUBY_ENGINE == "truffleruby" && RUBY_ENGINE_VERSION < "21.1.0") ||
43
- RUBY_VERSION < "2.3"
30
+ if RUBY_ENGINE == "jruby"
31
+ # In JRuby, sendmsg_nonblock is not implemented
44
32
  def write(buffer)
45
- siz = @io.sendmsg_nonblock(buffer.to_s, 0, Socket.sockaddr_in(@port, @host.to_s))
33
+ siz = @io.send(buffer.to_s, 0, @host, @port)
46
34
  log { "WRITE: #{siz} bytes..." }
47
35
  buffer.shift!(siz)
48
36
  siz
49
- rescue ::IO::WaitWritable
50
- 0
51
- rescue EOFError
52
- nil
53
- end
54
-
55
- def read(size, buffer)
56
- data, _ = @io.recvfrom_nonblock(size)
57
- buffer.replace(data)
58
- log { "READ: #{buffer.bytesize} bytes..." }
59
- buffer.bytesize
60
- rescue ::IO::WaitReadable
61
- 0
62
- rescue IOError
63
37
  end
64
38
  else
65
-
66
39
  def write(buffer)
67
40
  siz = @io.sendmsg_nonblock(buffer.to_s, 0, Socket.sockaddr_in(@port, @host.to_s), exception: false)
68
41
  return 0 if siz == :wait_writable
@@ -73,24 +46,17 @@ module HTTPX
73
46
  buffer.shift!(siz)
74
47
  siz
75
48
  end
49
+ end
76
50
 
77
- def read(size, buffer)
78
- ret = @io.recvfrom_nonblock(size, 0, buffer, exception: false)
79
- return 0 if ret == :wait_readable
80
- return if ret.nil?
51
+ def read(size, buffer)
52
+ ret = @io.recvfrom_nonblock(size, 0, buffer, exception: false)
53
+ return 0 if ret == :wait_readable
54
+ return if ret.nil?
81
55
 
82
- buffer.bytesize
83
- rescue IOError
84
- end
85
- end
56
+ log { "READ: #{buffer.bytesize} bytes..." }
86
57
 
87
- # In JRuby, sendmsg_nonblock is not implemented
88
- def write(buffer)
89
- siz = @io.send(buffer.to_s, 0, @host, @port)
90
- log { "WRITE: #{siz} bytes..." }
91
- buffer.shift!(siz)
92
- siz
93
- end if RUBY_ENGINE == "jruby"
94
- # :nocov:
58
+ buffer.bytesize
59
+ rescue IOError
60
+ end
95
61
  end
96
62
  end
data/lib/httpx/io/unix.rb CHANGED
@@ -1,22 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "forwardable"
4
-
5
3
  module HTTPX
6
4
  class UNIX < TCP
7
- extend Forwardable
8
-
9
5
  using URIExtensions
10
6
 
11
7
  attr_reader :path
12
8
 
13
9
  alias_method :host, :path
14
10
 
15
- def initialize(origin, addresses, options)
16
- @addresses = addresses
11
+ def initialize(origin, path, options)
12
+ @addresses = []
17
13
  @hostname = origin.host
18
14
  @state = :idle
19
- @options = Options.new(options)
15
+ @options = options
20
16
  @fallback_protocol = @options.fallback_protocol
21
17
  if @options.io
22
18
  @io = case @options.io
@@ -30,15 +26,10 @@ module HTTPX
30
26
  @path = @io.path
31
27
  @keep_open = true
32
28
  @state = :connected
29
+ elsif path
30
+ @path = path
33
31
  else
34
- if @options.transport_options
35
- # :nocov:
36
- warn ":#{__method__} is deprecated, use :addresses instead"
37
- @path = @options.transport_options[:path]
38
- # :nocov:
39
- else
40
- @path = addresses.first
41
- end
32
+ raise Error, "No path given where to store the socket"
42
33
  end
43
34
  @io ||= build_socket
44
35
  end
@@ -60,6 +51,10 @@ module HTTPX
60
51
  ::IO::WaitReadable
61
52
  end
62
53
 
54
+ def expired?
55
+ false
56
+ end
57
+
63
58
  # :nocov:
64
59
  def inspect
65
60
  "#<#{self.class}(path: #{@path}): (state: #{@state})>"
data/lib/httpx/io.rb CHANGED
@@ -4,14 +4,8 @@ require "socket"
4
4
  require "httpx/io/udp"
5
5
  require "httpx/io/tcp"
6
6
  require "httpx/io/unix"
7
- require "httpx/io/ssl"
8
7
 
9
- module HTTPX
10
- module IO
11
- extend Registry
12
- register "udp", UDP
13
- register "unix", HTTPX::UNIX
14
- register "tcp", TCP
15
- register "ssl", SSL
16
- end
8
+ begin
9
+ require "httpx/io/ssl"
10
+ rescue LoadError
17
11
  end
@@ -24,26 +24,11 @@ module HTTPX
24
24
  debug_stream << message
25
25
  end
26
26
 
27
- if Exception.instance_methods.include?(:full_message)
28
-
29
- def log_exception(ex, level: @options.debug_level, color: nil)
30
- return unless @options.debug
31
- return unless @options.debug_level >= level
32
-
33
- log(level: level, color: color) { ex.full_message }
34
- end
35
-
36
- else
37
-
38
- def log_exception(ex, level: @options.debug_level, color: nil)
39
- return unless @options.debug
40
- return unless @options.debug_level >= level
41
-
42
- message = +"#{ex.message} (#{ex.class})"
43
- message << "\n" << ex.backtrace.join("\n") unless ex.backtrace.nil?
44
- log(level: level, color: color) { message }
45
- end
27
+ def log_exception(ex, level: @options.debug_level, color: nil)
28
+ return unless @options.debug
29
+ return unless @options.debug_level >= level
46
30
 
31
+ log(level: level, color: color) { ex.full_message }
47
32
  end
48
33
  end
49
34
  end