Permalink
Browse files

Fix #15, Support multipart post.

  • Loading branch information...
1 parent e318a72 commit 9c1cbb81c9a8b45bd5ea80f20d5220c8d97384ec @jiangmiao committed Apr 9, 2013
Showing with 239 additions and 30 deletions.
  1. +2 −2 binding.gyp
  2. +4 −6 examples/curl.js
  3. +0 −1 examples/low-level.js
  4. +27 −0 examples/post-multi-part.js
  5. +12 −0 examples/post-multi-part.toffee
  6. +7 −9 examples/test.js
  7. +42 −5 lib/Curl.js
  8. +27 −1 lib/Curl.toffee
  9. +6 −6 lib/CurlBuilder.js
  10. +112 −0 src/node-curl.h
View
@@ -2,8 +2,8 @@
'targets': [
{
'target_name': 'node-curl',
- 'cflags': ['-Wall', '-O1', '-fno-inline-functions'],
- 'cflags_cc': ['-Wall', '-O1', '-fno-inline-functions'],
+ 'cflags': ['-Wall', '-O1', '-g', '-fno-inline-functions'],
+ 'cflags_cc': ['-Wall', '-O1', '-g', '-fno-inline-functions'],
'sources': ['src/node-curl.cc'],
'libraries': ['-lcurl']
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -21,7 +21,6 @@ curl.on('data', function(chunk) {
curl.on('error', function(e) {
p("error: " + e.message);
curl.close();
- once();
});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,12 @@
+curl = require '../index'
+p = console.log
+p 'start'
+
+curl '127.0.0.1/upload.php', {
+ multipart: [
+ {name: 'file', file: '/home/miao/test.js', type: 'text/html'},
+ {name: 'sumbit', value: 'send'}
+ ],
+}, (e) ->
+ console.log e
+ console.log curl.body
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -6,13 +6,38 @@ catch e
Curl::setopt_user_ = (option_id, value) ->
@options[option_id] = value
+Curl::setopt_httppost = (rows) ->
+ # convert object-rows to array-rows
+ # format
+ # [
+ # [OPTION_ID, VALUE]
+ # ]
+ @httppost = for row in rows
+ cols = []
+ for own k, v of row
+ k = k.toUpperCase()
+ if (option_id = Curl.httppost_options[k])?
+ cols.push option_id
+ unless v instanceof Buffer
+ v = new Buffer(v.toString())
+ cols.push v
+ else
+ throw new Error("invalid http post option #{k}")
+ cols
+ @setopt_httppost_(@httppost)
+ @
+
+
Curl::setopt = (option_name, value) ->
option = option_name.toUpperCase()
# slist must be at the top of condition
# the option exists in string_options too
if (option_id = Curl.user_options[option])?
- @setopt_user_ option_id, value
+ if (option == 'MULTIPART')
+ @setopt_httppost value
+ else
+ @setopt_user_ option_id, value
else if (option_id = Curl.slist_options[option])?
@setopt_slist_ option_id, value
else if (option_id = Curl.integer_options[option])?
@@ -41,6 +66,7 @@ Curl::getinfo = (oinfo) ->
Curl.user_options =
RAW: 'RAW'
DEBUG: 'DEBUG'
+ MULTIPART: 'MULTIPART'
id = 0
curls = {}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 9c1cbb8

Please sign in to comment.