Skip to content

Commit f1d8ac9

Browse files
committed
fix pubsub
- content type was being passed but ignored - jsonize was overwriting every non-json body for non-get requests
1 parent 9874b91 commit f1d8ac9

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

lib/github_api/connection.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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

lib/github_api/request/jsonize.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)