Permalink
Browse files

Merge pull request #57 from windy/master

fix get_file give wrong file because of calling fopen 'w', always on windows
  • Loading branch information...
2 parents 6214c29 + 0aa6085 commit 411cd7c9e32a670bc67df7ecfbbe52df15d9d88a @toland committed Mar 20, 2012
Showing with 11 additions and 3 deletions.
  1. +3 −3 ext/patron/session_ext.c
  2. +8 −0 spec/session_spec.rb
View
@@ -354,7 +354,7 @@ static void set_options_from_request(VALUE self, VALUE request) {
curl_easy_setopt(curl, CURLOPT_INFILESIZE, len);
}
if (!NIL_P(download_file)) {
- state->download_file = open_file(download_file, "w");
+ state->download_file = open_file(download_file, "wb");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, state->download_file);
} else {
state->download_file = NULL;
@@ -388,7 +388,7 @@ static void set_options_from_request(VALUE self, VALUE request) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
}
- state->upload_file = open_file(filename, "r");
+ state->upload_file = open_file(filename, "rb");
curl_easy_setopt(curl, CURLOPT_READDATA, state->upload_file);
} else if (!NIL_P(multipart)) {
if (action == rb_intern("POST")) {
@@ -673,7 +673,7 @@ static VALUE set_debug_file(VALUE self, VALUE file) {
session_close_debug_file(state);
if(file_path != NULL && strlen(file_path) != 0) {
- state->debug_file = open_file(file, "w");
+ state->debug_file = open_file(file, "wb");
} else {
state->debug_file = stderr;
}
View
@@ -65,6 +65,14 @@
FileUtils.rm tmpfile
end
+ it "should download correctly(md5 ok) with get_file" do
+ tmpfile = "/tmp/picture"
+ response = @session.get_file "/picture", tmpfile
+ response.body.should be_nil
+ File.size(File.join(File.dirname(__FILE__),"../pic.png")).should == File.size(tmpfile)
+ FileUtils.rm tmpfile
+ end
+
it "should include custom headers in a request" do
response = @session.get("/test", {"User-Agent" => "PatronTest"})
body = YAML::load(response.body)

0 comments on commit 411cd7c

Please sign in to comment.