Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gmarik/702962 to your computer and use it in GitHub Desktop.
Save gmarik/702962 to your computer and use it in GitHub Desktop.
From 6737da2323d9896fe30de66394a659de2b41e9b1 Mon Sep 17 00:00:00 2001
From: gmarik <[email protected]>
Date: Tue, 16 Nov 2010 22:05:27 -0600
Subject: [PATCH] Do not set Content-Type header when body defined
---
platform/shared/net/AsyncHttp.cpp | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/platform/shared/net/AsyncHttp.cpp b/platform/shared/net/AsyncHttp.cpp
index e86ace9..2602a81 100644
--- a/platform/shared/net/AsyncHttp.cpp
+++ b/platform/shared/net/AsyncHttp.cpp
@@ -138,7 +138,6 @@ void CAsyncHttp::CHttpCommand::execute()
if ( strBody.length() > 0 )
{
pItem->m_strBody = strBody;
- pItem->m_strContentType = oItem.getString("content_type", "application/x-www-form-urlencoded");
}
else
{
--
1.7.3.1

I'm trying to test multipart post with:

 Rho::AsyncHttp.upload_file(
   :url => 'http://my_uri_here/',
   :multipart => [
     {
       :filename => File.join(Rho::RhoApplication::get_base_app_path(), 'rhoconfig.txt'),
       :name => "model[file]",
     },
     {
          :body => "upload test",
          :name => "model[text]", # optional, 'blob' used as default
          #:content_type => "plain/text" # optional, 'application/x-www-form-urlencoded' used as default
     }])

and on backend server(running rails 3) I get error:

 NoMethodError (undefined method `rewind' for "upload test":String)

SOME DEBUGGGING

AsynHttp requrest(stripped)
   POST /account/1/bills HTTP/1.1
   Host: 192.168.0.101:3000
   Accept: */*
   Accept-Encoding: deflate, gzip
   Connection: Keep-Alive
   User-Agent: Mozilla-5.0 (ANDROID; generic; 2.2)
   Content-Length: 860
   Content-Type: multipart/form-data; boundary=----------------------------11a1a536b694
   
    ------------------------------11a1a536b694
   Content-Disposition: form-data; name="bill[file]"; filename="rhoconfig.txt"
   Content-Type: application/octet-stream
   Content-Length: 449
   
   # syncserver='http://rhodes-samples-server.heroku.com/application'
   ...

   ------------------------------11a1a536b694
   Content-Disposition: form-data; name="bill[text]"
   Content-Type: application/x-www-form-urlencoded
   Content-Length: 11
   
   upload test
   ------------------------------11a1a536b694--

CURL Request

 curl --trace-ascii out  -F "bill[file]=@README" -F "bill[text]=test" http://localhost:3000/account/1/bills 


   POST /account/1/bills HTTP/1.1
   User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.1
   9.7 OpenSSL/0.9.8l zlib/1.2.3
   Host: localhost:3000
   Accept: */*
   Content-Length: 9437
   Expect: 100-continue
   Content-Type: multipart/form-data; boundary=--------------------
   --------c4c4ba95406f
   
   ------------------------------c4c4ba95406f
   Content-Disposition: form-data; name="bill[file]"; filename="README"
   Content-Type: application/octet-stream
   
   file content here....
   
   ------------------------------c4c4ba95406f
   Content-Disposition: form-data; name="bill[text]"
   
   upload test
   ------------------------------c4c4ba95406f--

Conclusion

Content-Type header should not be present, when multipart body is set ( name[text]=upload test )

That's what curl's request headers say, and what Rack::Utils.process_multipart expects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment