philiprehberger-http_client 0.10.0 → 0.11.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/README.md +15 -6
- data/lib/philiprehberger/http_client/response.rb +15 -4
- data/lib/philiprehberger/http_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5438d46ef6a929e6272a230dc19c64a50ff6c183b96cbec03b6379f1dec476df
|
|
4
|
+
data.tar.gz: 256673e0413568cfaafc4a4fbbba15d0fbdffe60c0aca1d22090909c2db24a16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb20cd1a0bd5020afc0e519d6b02ae078fa19266ae829f201baf607b8b4b8dce1e1bdd73d80110739dbd04b2d8bcdc9e235b64ad9ed528be0efcecb9a8e52e54
|
|
7
|
+
data.tar.gz: 81e1cdcef88ee36d4a585bd8ae6f190e61641ae0f7575b416dca40abbe389aadc4bdd7cf4a632a3778bb580333422cdbf7338f1afb268a225ee8c26767609f8e
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.11.1] - 2026-06-14
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- Added package card image to README
|
|
14
|
+
- Cleaned up Installation section formatting
|
|
15
|
+
|
|
16
|
+
## [0.11.0] - 2026-05-13
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- `Response#header(name)` — case-insensitive header value accessor. Returns `nil` when the header is absent.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- `Response#json?` now delegates to `Response#header` for Content-Type lookup.
|
|
23
|
+
|
|
10
24
|
## [0.10.0] - 2026-05-07
|
|
11
25
|
|
|
12
26
|
### Added
|
|
@@ -186,7 +200,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
186
200
|
- Response wrapper with `ok?` and `json` convenience methods
|
|
187
201
|
- Zero dependencies — built on Ruby stdlib `net/http`
|
|
188
202
|
|
|
189
|
-
[Unreleased]: https://github.com/philiprehberger/rb-http-client/compare/v0.
|
|
203
|
+
[Unreleased]: https://github.com/philiprehberger/rb-http-client/compare/v0.11.1...HEAD
|
|
204
|
+
[0.11.1]: https://github.com/philiprehberger/rb-http-client/compare/v0.11.0...v0.11.1
|
|
205
|
+
[0.11.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.10.0...v0.11.0
|
|
190
206
|
[0.10.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.9.1...v0.10.0
|
|
191
207
|
[0.9.1]: https://github.com/philiprehberger/rb-http-client/compare/v0.9.0...v0.9.1
|
|
192
208
|
[0.9.0]: https://github.com/philiprehberger/rb-http-client/compare/v0.8.2...v0.9.0
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-http_client)
|
|
5
5
|
[](https://github.com/philiprehberger/rb-http-client/commits/main)
|
|
6
6
|
|
|
7
|
+

|
|
8
|
+
|
|
7
9
|
Lightweight HTTP client wrapper with retries and interceptors
|
|
8
10
|
|
|
9
11
|
## Requirements
|
|
@@ -18,12 +20,6 @@ Add to your Gemfile:
|
|
|
18
20
|
gem "philiprehberger-http_client"
|
|
19
21
|
```
|
|
20
22
|
|
|
21
|
-
Then run:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
bundle install
|
|
25
|
-
```
|
|
26
|
-
|
|
27
23
|
Or install directly:
|
|
28
24
|
|
|
29
25
|
```bash
|
|
@@ -424,6 +420,18 @@ client.delete("/resource/1")
|
|
|
424
420
|
client.head("/resource")
|
|
425
421
|
```
|
|
426
422
|
|
|
423
|
+
### Case-insensitive header lookup
|
|
424
|
+
|
|
425
|
+
`Response#header` returns the value for a header regardless of capitalization, returning `nil` when it is missing:
|
|
426
|
+
|
|
427
|
+
```ruby
|
|
428
|
+
response = client.head("/resource")
|
|
429
|
+
|
|
430
|
+
response.header("Content-Type") # => "application/json"
|
|
431
|
+
response.header("etag") # works for any casing
|
|
432
|
+
response.header("X-Missing") # => nil
|
|
433
|
+
```
|
|
434
|
+
|
|
427
435
|
## API
|
|
428
436
|
|
|
429
437
|
### `Philiprehberger::HttpClient.new(**options)`
|
|
@@ -493,6 +501,7 @@ client.head("/resource")
|
|
|
493
501
|
| `status` | Integer | HTTP status code |
|
|
494
502
|
| `body` | String | Raw response body (`nil` if streamed) |
|
|
495
503
|
| `headers` | Hash | Response headers |
|
|
504
|
+
| `header(name)` | String | Header value for `name` (case-insensitive), `nil` if absent |
|
|
496
505
|
| `ok?` | Boolean | `true` if status is 200-299 |
|
|
497
506
|
| `client_error?` | Boolean | Returns true for 4xx status codes |
|
|
498
507
|
| `server_error?` | Boolean | Returns true for 5xx status codes |
|
|
@@ -58,6 +58,17 @@ module Philiprehberger
|
|
|
58
58
|
@json ||= JSON.parse(body)
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
# Returns the header value for `name`, matching case-insensitively.
|
|
62
|
+
# Returns `nil` when the header is not present.
|
|
63
|
+
#
|
|
64
|
+
# @param name [String, Symbol] header name (case-insensitive)
|
|
65
|
+
# @return [String, nil]
|
|
66
|
+
def header(name)
|
|
67
|
+
key = name.to_s.downcase
|
|
68
|
+
headers.each { |k, v| return v if k.to_s.downcase == key }
|
|
69
|
+
nil
|
|
70
|
+
end
|
|
71
|
+
|
|
61
72
|
# Returns true if the `Content-Type` response header advertises JSON.
|
|
62
73
|
# Matches `application/json`, `application/problem+json`, and any
|
|
63
74
|
# other `+json` structured-syntax suffix defined by RFC 6838.
|
|
@@ -65,11 +76,11 @@ module Philiprehberger
|
|
|
65
76
|
#
|
|
66
77
|
# @return [Boolean]
|
|
67
78
|
def json?
|
|
68
|
-
|
|
69
|
-
return false unless
|
|
79
|
+
value = header('content-type')
|
|
80
|
+
return false unless value
|
|
70
81
|
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
primary = value.to_s.downcase.split(';').first.to_s.strip
|
|
83
|
+
primary == 'application/json' || primary.end_with?('+json')
|
|
73
84
|
end
|
|
74
85
|
|
|
75
86
|
# Returns request timing metrics (nil if not available).
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-http_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A zero-dependency HTTP client built on Ruby's net/http with automatic
|
|
14
14
|
retries, request/response interceptors, and a clean API for JSON services.
|