@@ -90,9 +90,14 @@ pub struct Easy {
90
90
/// The callbacks attached to a `Transfer` are only active for that one transfer
91
91
/// object, and they allow to elide both the `Send` and `'static` bounds to
92
92
/// close over stack-local information.
93
+ ///
94
+ /// Likewise, the post_data attached to a `Transfer` are only active for that one
95
+ /// transfer object, and they allow to elide both the `Send` and `'static` bounds
96
+ /// to close over stack-local information.
93
97
pub struct Transfer < ' easy , ' data > {
94
98
easy : & ' easy mut Easy ,
95
- data : Box < Callbacks < ' data > > ,
99
+ callbacks : Box < Callbacks < ' data > > ,
100
+ is_postfields : Cell < bool > ,
96
101
}
97
102
98
103
pub struct EasyData {
@@ -719,6 +724,11 @@ impl Easy {
719
724
self . inner . post_fields_copy ( data)
720
725
}
721
726
727
+ /// Same as [`Easy2::post_field`](struct.Easy2.html#method.post_field)
728
+ pub fn post_fields ( & mut self , data : & ' static [ u8 ] ) -> Result < ( ) , Error > {
729
+ self . inner . post_fields ( data)
730
+ }
731
+
722
732
/// Same as [`Easy2::post_field_size`](struct.Easy2.html#method.post_field_size)
723
733
pub fn post_field_size ( & mut self , size : u64 ) -> Result < ( ) , Error > {
724
734
self . inner . post_field_size ( size)
@@ -1216,8 +1226,9 @@ impl Easy {
1216
1226
pub fn transfer < ' data , ' easy > ( & ' easy mut self ) -> Transfer < ' easy , ' data > {
1217
1227
assert ! ( !self . inner. get_ref( ) . running. get( ) ) ;
1218
1228
Transfer {
1219
- data : Box :: new ( Callbacks :: default ( ) ) ,
1229
+ callbacks : Box :: new ( Callbacks :: default ( ) ) ,
1220
1230
easy : self ,
1231
+ is_postfields : Cell :: new ( false ) ,
1221
1232
}
1222
1233
}
1223
1234
@@ -1379,7 +1390,7 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1379
1390
where
1380
1391
F : FnMut ( & [ u8 ] ) -> Result < usize , WriteError > + ' data ,
1381
1392
{
1382
- self . data . write = Some ( Box :: new ( f) ) ;
1393
+ self . callbacks . write = Some ( Box :: new ( f) ) ;
1383
1394
Ok ( ( ) )
1384
1395
}
1385
1396
@@ -1389,7 +1400,7 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1389
1400
where
1390
1401
F : FnMut ( & mut [ u8 ] ) -> Result < usize , ReadError > + ' data ,
1391
1402
{
1392
- self . data . read = Some ( Box :: new ( f) ) ;
1403
+ self . callbacks . read = Some ( Box :: new ( f) ) ;
1393
1404
Ok ( ( ) )
1394
1405
}
1395
1406
@@ -1399,7 +1410,7 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1399
1410
where
1400
1411
F : FnMut ( SeekFrom ) -> SeekResult + ' data ,
1401
1412
{
1402
- self . data . seek = Some ( Box :: new ( f) ) ;
1413
+ self . callbacks . seek = Some ( Box :: new ( f) ) ;
1403
1414
Ok ( ( ) )
1404
1415
}
1405
1416
@@ -1409,7 +1420,7 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1409
1420
where
1410
1421
F : FnMut ( f64 , f64 , f64 , f64 ) -> bool + ' data ,
1411
1422
{
1412
- self . data . progress = Some ( Box :: new ( f) ) ;
1423
+ self . callbacks . progress = Some ( Box :: new ( f) ) ;
1413
1424
Ok ( ( ) )
1414
1425
}
1415
1426
@@ -1419,7 +1430,7 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1419
1430
where
1420
1431
F : FnMut ( * mut c_void ) -> Result < ( ) , Error > + Send + ' data ,
1421
1432
{
1422
- self . data . ssl_ctx = Some ( Box :: new ( f) ) ;
1433
+ self . callbacks . ssl_ctx = Some ( Box :: new ( f) ) ;
1423
1434
Ok ( ( ) )
1424
1435
}
1425
1436
@@ -1429,7 +1440,7 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1429
1440
where
1430
1441
F : FnMut ( InfoType , & [ u8 ] ) + ' data ,
1431
1442
{
1432
- self . data . debug = Some ( Box :: new ( f) ) ;
1443
+ self . callbacks . debug = Some ( Box :: new ( f) ) ;
1433
1444
Ok ( ( ) )
1434
1445
}
1435
1446
@@ -1439,7 +1450,7 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1439
1450
where
1440
1451
F : FnMut ( & [ u8 ] ) -> bool + ' data ,
1441
1452
{
1442
- self . data . header = Some ( Box :: new ( f) ) ;
1453
+ self . callbacks . header = Some ( Box :: new ( f) ) ;
1443
1454
Ok ( ( ) )
1444
1455
}
1445
1456
@@ -1454,7 +1465,7 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1454
1465
// This should be ok, however, because `do_perform` checks for recursive
1455
1466
// invocations of `perform` and disallows them. Our type also isn't
1456
1467
// `Sync`.
1457
- inner. borrowed . set ( & * self . data as * const _ as * mut _ ) ;
1468
+ inner. borrowed . set ( & * self . callbacks as * const _ as * mut _ ) ;
1458
1469
1459
1470
// Make sure to reset everything back to the way it was before when
1460
1471
// we're done.
@@ -1466,7 +1477,21 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1466
1477
}
1467
1478
let _reset = Reset ( & inner. borrowed ) ;
1468
1479
1469
- self . easy . do_perform ( )
1480
+ let res = self . easy . do_perform ( ) ;
1481
+
1482
+ // restore configuration
1483
+ if self . is_postfields . get ( ) {
1484
+ self . easy
1485
+ . inner
1486
+ . setopt_ptr ( curl_sys:: CURLOPT_POSTFIELDS , 0 as * const _ )
1487
+ . expect ( "Failed to reset post_field_size" ) ;
1488
+ self . easy
1489
+ . inner
1490
+ . setopt_ptr ( curl_sys:: CURLOPT_POSTFIELDS , ptr:: null ( ) as * const _ )
1491
+ . expect ( "Failed to set postfields to null" ) ;
1492
+ self . is_postfields . set ( false ) ;
1493
+ }
1494
+ res
1470
1495
}
1471
1496
1472
1497
/// Same as `Easy::unpause_read`.
@@ -1478,6 +1503,17 @@ impl<'easy, 'data> Transfer<'easy, 'data> {
1478
1503
pub fn unpause_write ( & self ) -> Result < ( ) , Error > {
1479
1504
self . easy . unpause_write ( )
1480
1505
}
1506
+
1507
+ /// Similar to [`Easy2::post_field`](struct.Easy2.html#method.post_field) just
1508
+ /// takes a non `'static` lifetime corresponding to the lifetime of this transfer.
1509
+ pub fn post_fields ( & mut self , data : & ' data [ u8 ] ) -> Result < ( ) , Error > {
1510
+ // Set the length before the pointer so libcurl knows how much to read
1511
+ self . is_postfields . set ( true ) ;
1512
+ self . easy . inner . post_field_size ( data. len ( ) as u64 ) ?;
1513
+ self . easy
1514
+ . inner
1515
+ . setopt_ptr ( curl_sys:: CURLOPT_POSTFIELDS , data. as_ptr ( ) as * const _ )
1516
+ }
1481
1517
}
1482
1518
1483
1519
impl < ' easy , ' data > fmt:: Debug for Transfer < ' easy , ' data > {
0 commit comments