net.http: fix compilation of trivial examples with `v -cflags -Werror`

pull/8906/head
Delyan Angelov 2021-02-22 17:11:02 +02:00
parent 7c97b0b24d
commit b01a302a4e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 6 additions and 7 deletions

View File

@ -12,8 +12,7 @@ const (
fn (req &Request) ssl_do(port int, method Method, host_name string, path string) ?Response { fn (req &Request) ssl_do(port int, method Method, host_name string, path string) ?Response {
// ssl_method := C.SSLv23_method() // ssl_method := C.SSLv23_method()
ssl_method := C.TLSv1_2_method() ctx := C.SSL_CTX_new(C.TLSv1_2_method())
ctx := C.SSL_CTX_new(ssl_method)
C.SSL_CTX_set_verify_depth(ctx, 4) C.SSL_CTX_set_verify_depth(ctx, 4)
flags := C.SSL_OP_NO_SSLv2 | C.SSL_OP_NO_SSLv3 | C.SSL_OP_NO_COMPRESSION flags := C.SSL_OP_NO_SSLv2 | C.SSL_OP_NO_SSLv3 | C.SSL_OP_NO_COMPRESSION
C.SSL_CTX_set_options(ctx, flags) C.SSL_CTX_set_options(ctx, flags)
@ -24,21 +23,21 @@ fn (req &Request) ssl_do(port int, method Method, host_name string, path string)
ssl := &openssl.SSL(0) ssl := &openssl.SSL(0)
C.BIO_get_ssl(web, &ssl) C.BIO_get_ssl(web, &ssl)
preferred_ciphers := 'HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4' preferred_ciphers := 'HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4'
res = C.SSL_set_cipher_list(ssl, preferred_ciphers.str) res = C.SSL_set_cipher_list(voidptr(ssl), preferred_ciphers.str)
if res != 1 { if res != 1 {
println('http: openssl: cipher failed') println('http: openssl: cipher failed')
} }
res = C.SSL_set_tlsext_host_name(ssl, host_name.str) res = C.SSL_set_tlsext_host_name(voidptr(ssl), host_name.str)
res = C.BIO_do_connect(web) res = C.BIO_do_connect(web)
if res != 1 { if res != 1 {
return error('cannot connect the endpoint') return error('cannot connect the endpoint')
} }
res = C.BIO_do_handshake(web) res = C.BIO_do_handshake(web)
C.SSL_get_peer_certificate(ssl) C.SSL_get_peer_certificate(voidptr(ssl))
res = C.SSL_get_verify_result(ssl) res = C.SSL_get_verify_result(voidptr(ssl))
// ///// // /////
req_headers := req.build_request_headers(method, host_name, path) req_headers := req.build_request_headers(method, host_name, path)
//println(req_headers) // println(req_headers)
C.BIO_puts(web, req_headers.str) C.BIO_puts(web, req_headers.str)
mut content := strings.new_builder(100) mut content := strings.new_builder(100)
mut buff := [bufsize]byte{} mut buff := [bufsize]byte{}