Skip to content

Commit

Permalink
Address Code Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Aug 9, 2021
1 parent 13c077e commit f74a9da
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/middleware/request/authentication.md
Expand Up @@ -9,8 +9,8 @@ top_name: Back to Middleware
top_link: ./list
---

Basic and Token authentication are handled by Faraday::Request::BasicAuthentication
and Faraday::Request::TokenAuthentication respectively.
Basic and Token authentication are handled by `Faraday::Request::BasicAuthentication`
and `Faraday::Request::TokenAuthentication` respectively.
These can be added as middleware manually or through the helper methods.

### Basic Authentication
Expand Down
2 changes: 1 addition & 1 deletion docs/middleware/request/json.md
Expand Up @@ -11,7 +11,7 @@ top_name: Back to Middleware
top_link: ./list
---

The `Json Request` middleware converts a `Faraday::Request#body` hash of key/value pairs into a JSON request body.
The `JSON` request middleware converts a `Faraday::Request#body` hash of key/value pairs into a JSON request body.
The middleware also automatically sets the `Content-Type` header to `application/json`,
processes only requests with matching Content-Type or those without a type and
doesn't try to encode bodies that already are in string form.
Expand Down
8 changes: 4 additions & 4 deletions docs/middleware/response/json.md
Expand Up @@ -11,11 +11,11 @@ top_name: Back to Middleware
top_link: ./list
---

The `Json Response` middleware parses response body into a hash of key/value pairs.
The `JSON` response middleware parses response body into a hash of key/value pairs.
The behaviour can be customized with the following options:
* **parser_options:** options that will be sent to the JSON.parse method. Defaults to {}
* **content_type:** Single value or Array of response content-types that should be processed. Can be either strings or Regex. Defaults to `/\bjson$/`
* **preserve_raw:** If set to true, the original un-parsed response will be stored in the `response.env[:raw_body]` property. Defaults to `false`
* **parser_options:** options that will be sent to the JSON.parse method. Defaults to {}.
* **content_type:** Single value or Array of response content-types that should be processed. Can be either strings or Regex. Defaults to `/\bjson$/`.
* **preserve_raw:** If set to true, the original un-parsed response will be stored in the `response.env[:raw_body]` property. Defaults to `false`.

### Example Usage

Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/request/json.rb
Expand Up @@ -36,7 +36,7 @@ def match_content_type(env)

def process_request?(env)
type = request_type(env)
body?(env) && (type.empty? || MIME_TYPE_REGEX =~ type)
body?(env) && (type.empty? || type.match?(MIME_TYPE_REGEX))
end

def body?(env)
Expand Down
2 changes: 1 addition & 1 deletion lib/faraday/response/json.rb
Expand Up @@ -38,7 +38,7 @@ def parse_response?(env)
def process_response_type?(env)
type = response_type(env)
@content_types.empty? || @content_types.any? do |pattern|
pattern.is_a?(Regexp) ? type =~ pattern : type == pattern
pattern.is_a?(Regexp) ? type.match?(pattern) : type == pattern
end
end

Expand Down
1 change: 0 additions & 1 deletion spec/faraday/response/json_spec.rb
Expand Up @@ -4,7 +4,6 @@
let(:options) { {} }
let(:headers) { {} }
let(:middleware) do
puts options
described_class.new(lambda { |env|
Faraday::Response.new(env)
}, **options)
Expand Down

0 comments on commit f74a9da

Please sign in to comment.