Permalink
Browse files

Set 'Content-Type: application/json' [Fixes #7]

The issue was that Net::HTTP sets the default content-type to
application/x-www-form-encoded, which caused GitHub's servers to
percent-decode the incoming content.

This meant that if a file contained a % that was not followed by two hex
digits, you could not upload a gist. Setting the right content-type
header fixes this.

Thanks to @rking for the data to replicate this problem.
  • Loading branch information...
1 parent 1d8c2ef commit 75a5731d9c438d4e1fcfb57d727d143156b31255 @ConradIrwin committed Jul 24, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/jist.rb
View
@@ -5,7 +5,7 @@
# It just gists.
module Jist
- VERSION = '0.9.1'
+ VERSION = '0.9.2'
# Exception tag for errors raised while gisting.
module Error; end
@@ -72,6 +72,7 @@ def multi_gist(files, options={})
request = Net::HTTP::Post.new(url)
request.body = JSON.dump(json)
+ request.content_type = 'application/json'
retried = false
@@ -118,6 +119,7 @@ def login!
:note => "The jist gem",
:note_url => "https://github.com/ConradIrwin/jist"
})
+ request.content_type = 'application/json'
request.basic_auth(username, password)
response = http(request)

0 comments on commit 75a5731

Please sign in to comment.