File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,7 +26,12 @@ def default_options(options = {})
2626 } ,
2727 ssl : options [ :ssl ] ,
2828 url : options [ :endpoint ]
29- }
29+ } . tap do |h |
30+ if type = options [ :headers ] && options [ :headers ] [ CONTENT_TYPE ]
31+ h [ :headers ] [ CONTENT_TYPE ] = type
32+ end
33+ h
34+ end
3035 end
3136
3237 def clear_cache
Original file line number Diff line number Diff line change @@ -14,9 +14,9 @@ def call(env)
1414 if request_with_body? ( env )
1515 env [ :request_headers ] [ CONTENT_TYPE ] ||= MIME_TYPE
1616 env [ :body ] = encode_body env [ :body ] unless env [ :body ] . respond_to? ( :to_str )
17- else
17+ elsif safe_to_modify? ( env )
1818 # Ensure valid body for put and post requests
19- if [ :put , :patch , :post ] . include? env [ :method ]
19+ if [ :put , :patch , :post ] . include? ( env [ :method ] )
2020 env [ :body ] = encode_body ( { } )
2121 end
2222 end
@@ -33,7 +33,12 @@ def encode_body(value)
3333
3434 def request_with_body? ( env )
3535 type = request_type ( env )
36- has_body? ( env ) and ( type . empty? or type == MIME_TYPE )
36+ has_body? ( env ) and safe_to_modify? ( env )
37+ end
38+
39+ def safe_to_modify? ( env )
40+ type = request_type ( env )
41+ type . empty? or type == MIME_TYPE
3742 end
3843
3944 # Don't encode bodies in string form
You can’t perform that action at this time.
0 commit comments