1
1
use libc;
2
- use std :: ffi :: CString ;
2
+ use raw :: git_strarray ;
3
3
use std:: marker;
4
4
use std:: mem;
5
5
use std:: ops:: Range ;
6
6
use std:: ptr;
7
7
use std:: slice;
8
8
use std:: str;
9
+ use std:: { ffi:: CString , os:: raw:: c_char} ;
9
10
10
11
use crate :: string_array:: StringArray ;
11
12
use crate :: util:: Binding ;
@@ -43,13 +44,17 @@ pub struct FetchOptions<'cb> {
43
44
prune : FetchPrune ,
44
45
update_fetchhead : bool ,
45
46
download_tags : AutotagOption ,
47
+ custom_headers : Vec < CString > ,
48
+ custom_headers_ptrs : Vec < * const c_char > ,
46
49
}
47
50
48
51
/// Options to control the behavior of a git push.
49
52
pub struct PushOptions < ' cb > {
50
53
callbacks : Option < RemoteCallbacks < ' cb > > ,
51
54
proxy : Option < ProxyOptions < ' cb > > ,
52
55
pb_parallelism : u32 ,
56
+ custom_headers : Vec < CString > ,
57
+ custom_headers_ptrs : Vec < * const c_char > ,
53
58
}
54
59
55
60
/// Holds callbacks for a connection to a `Remote`. Disconnects when dropped
@@ -474,6 +479,8 @@ impl<'cb> FetchOptions<'cb> {
474
479
prune : FetchPrune :: Unspecified ,
475
480
update_fetchhead : true ,
476
481
download_tags : AutotagOption :: Unspecified ,
482
+ custom_headers : Vec :: new ( ) ,
483
+ custom_headers_ptrs : Vec :: new ( ) ,
477
484
}
478
485
}
479
486
@@ -511,6 +518,16 @@ impl<'cb> FetchOptions<'cb> {
511
518
self . download_tags = opt;
512
519
self
513
520
}
521
+
522
+ /// Set extra headers for this fetch operation.
523
+ pub fn custom_headers ( & mut self , custom_headers : & [ & str ] ) -> & mut Self {
524
+ self . custom_headers = custom_headers
525
+ . iter ( )
526
+ . map ( |& s| CString :: new ( s) . unwrap ( ) )
527
+ . collect ( ) ;
528
+ self . custom_headers_ptrs = self . custom_headers . iter ( ) . map ( |s| s. as_ptr ( ) ) . collect ( ) ;
529
+ self
530
+ }
514
531
}
515
532
516
533
impl < ' cb > Binding for FetchOptions < ' cb > {
@@ -535,10 +552,9 @@ impl<'cb> Binding for FetchOptions<'cb> {
535
552
prune : crate :: call:: convert ( & self . prune ) ,
536
553
update_fetchhead : crate :: call:: convert ( & self . update_fetchhead ) ,
537
554
download_tags : crate :: call:: convert ( & self . download_tags ) ,
538
- // TODO: expose this as a builder option
539
- custom_headers : raw:: git_strarray {
540
- count : 0 ,
541
- strings : ptr:: null_mut ( ) ,
555
+ custom_headers : git_strarray {
556
+ count : self . custom_headers_ptrs . len ( ) ,
557
+ strings : self . custom_headers_ptrs . as_ptr ( ) as * mut _ ,
542
558
} ,
543
559
}
544
560
}
@@ -557,6 +573,8 @@ impl<'cb> PushOptions<'cb> {
557
573
callbacks : None ,
558
574
proxy : None ,
559
575
pb_parallelism : 1 ,
576
+ custom_headers : Vec :: new ( ) ,
577
+ custom_headers_ptrs : Vec :: new ( ) ,
560
578
}
561
579
}
562
580
@@ -582,6 +600,16 @@ impl<'cb> PushOptions<'cb> {
582
600
self . pb_parallelism = parallel;
583
601
self
584
602
}
603
+
604
+ /// Set extra headers for this push operation.
605
+ pub fn custom_headers ( & mut self , custom_headers : & [ & str ] ) -> & mut Self {
606
+ self . custom_headers = custom_headers
607
+ . iter ( )
608
+ . map ( |& s| CString :: new ( s) . unwrap ( ) )
609
+ . collect ( ) ;
610
+ self . custom_headers_ptrs = self . custom_headers . iter ( ) . map ( |s| s. as_ptr ( ) ) . collect ( ) ;
611
+ self
612
+ }
585
613
}
586
614
587
615
impl < ' cb > Binding for PushOptions < ' cb > {
@@ -604,10 +632,9 @@ impl<'cb> Binding for PushOptions<'cb> {
604
632
. map ( |m| m. raw ( ) )
605
633
. unwrap_or_else ( || ProxyOptions :: new ( ) . raw ( ) ) ,
606
634
pb_parallelism : self . pb_parallelism as libc:: c_uint ,
607
- // TODO: expose this as a builder option
608
- custom_headers : raw:: git_strarray {
609
- count : 0 ,
610
- strings : ptr:: null_mut ( ) ,
635
+ custom_headers : git_strarray {
636
+ count : self . custom_headers_ptrs . len ( ) ,
637
+ strings : self . custom_headers_ptrs . as_ptr ( ) as * mut _ ,
611
638
} ,
612
639
}
613
640
}
0 commit comments