11package main
22
33import (
4+ "crypto/tls"
45 "flag"
56 "fmt"
67 "io"
@@ -14,8 +15,8 @@ import (
1415)
1516
1617var (
17- method , data , Cookie , Header string
18- Verbose bool
18+ method , data , Cookie , Header string
19+ Verbose , Https , UnsecureHttps bool
1920)
2021
2122func usage () {
@@ -29,6 +30,8 @@ func setupFlags() {
2930 flag .StringVar (& Header , "H" , "" , "Additional headers: k1:v1|k2:v2|..." )
3031 flag .StringVar (& Cookie , "b" , "" , "Add cookies: k1=v1|k2=v2|..." ) // b because thats what curl is
3132 flag .BoolVar (& Verbose , "v" , false , "Verbose information" )
33+ flag .BoolVar (& Https , "https" , false , "Make an HTTPS request" )
34+ flag .BoolVar (& UnsecureHttps , "k" , false , "Accept any certificate" )
3235 flag .Parse ()
3336}
3437
@@ -71,17 +74,17 @@ func main() {
7174 method = "POST"
7275 }
7376 // If data begins with @, it references a file
74- if ( string (data [0 ]) == "@" && len (data ) > 1 ) {
75- if ( string (data [1 :]) == "-" ) {
77+ if string (data [0 ]) == "@" && len (data ) > 1 {
78+ if string (data [1 :]) == "-" {
7679 buf , err := ioutil .ReadAll (os .Stdin )
77- if ( err != nil ) {
80+ if err != nil {
7881 fmt .Println ("Failed to read from stdin:" , err )
7982 os .Exit (1 )
8083 }
8184 reader = strings .NewReader (string (buf ))
8285 } else {
8386 buf , err := ioutil .ReadFile (string (data [1 :]))
84- if ( err != nil ) {
87+ if err != nil {
8588 fmt .Println ("Failed to open file:" , err )
8689 os .Exit (1 )
8790 }
@@ -108,11 +111,22 @@ func main() {
108111 os .Exit (1 )
109112 }
110113
111- conn , err := net .Dial ("unix" , u .Host )
114+ var conn net.Conn
115+ if Https {
116+ config := & tls.Config {}
117+ if UnsecureHttps {
118+ config .InsecureSkipVerify = true
119+ }
120+ conn , err = tls .Dial ("unix" , u .Host , config )
121+ } else {
122+ conn , err = net .Dial ("unix" , u .Host )
123+ }
124+
112125 if err != nil {
113126 fmt .Println ("Fail to connect to" , u .Host , ":" , err )
114127 os .Exit (1 )
115128 }
129+
116130 client := httputil .NewClientConn (conn , nil )
117131 res , err := requestExecute (conn , client , req )
118132 if err != nil {
0 commit comments