http: fix cookies

pull/5990/head^2
Alexander Medvednikov 2020-07-26 15:54:18 +02:00
parent 88345d759a
commit cf4235ab65
3 changed files with 18 additions and 8 deletions

View File

@ -38,6 +38,7 @@ fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response {
res = C.SSL_get_verify_result(ssl) res = C.SSL_get_verify_result(ssl)
// ///// // /////
req_headers := req.build_request_headers(method, host_name, path) req_headers := req.build_request_headers(method, host_name, path)
//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

View File

@ -49,7 +49,7 @@ pub:
pub fn new_request(method, url_, data string) ?Request { pub fn new_request(method, url_, data string) ?Request {
url := if method == 'GET' { url_ + '?' + data } else { url_ } url := if method == 'GET' { url_ + '?' + data } else { url_ }
//println('new req() method=$method url="$url" dta="$data"') println('new req() method=$method url="$url" dta="$data"')
return Request{ return Request{
method: method.to_upper() method: method.to_upper()
url: url url: url
@ -364,7 +364,7 @@ fn (req &Request) build_request_headers(method, host_name, path string) string {
if key == 'Cookie' { if key == 'Cookie' {
continue continue
} }
uheaders << '${key}: ${val}\r\n' uheaders << '${key}=${val}\r\n'
} }
uheaders << req.build_request_cookies_header() uheaders << req.build_request_cookies_header()
return '$method $path HTTP/1.1\r\n' + uheaders.join('') + 'Connection: close\r\n\r\n' + return '$method $path HTTP/1.1\r\n' + uheaders.join('') + 'Connection: close\r\n\r\n' +
@ -377,7 +377,7 @@ fn (req &Request) build_request_cookies_header() string {
} }
mut cookie := []string{} mut cookie := []string{}
for key, val in req.cookies { for key, val in req.cookies {
cookie << '$key: $val' cookie << '$key=$val'
} }
if 'Cookie' in req.headers && req.headers['Cookie'] != '' { if 'Cookie' in req.headers && req.headers['Cookie'] != '' {
cookie << req.headers['Cookie'] cookie << req.headers['Cookie']

View File

@ -24,7 +24,7 @@ mut:
pub mut: pub mut:
module_search_paths []string module_search_paths []string
parsed_files []ast.File parsed_files []ast.File
cached_msvc MsvcResult cached_msvc MsvcResult
table &table.Table table &table.Table
} }
@ -42,7 +42,9 @@ pub fn new_builder(pref &pref.Preferences) Builder {
if pref.ccompiler == 'msvc' { if pref.ccompiler == 'msvc' {
verror('Cannot find MSVC on this OS') verror('Cannot find MSVC on this OS')
} }
MsvcResult { valid: false } MsvcResult{
valid: false
}
} }
return Builder{ return Builder{
pref: pref pref: pref
@ -65,9 +67,14 @@ pub fn new_builder(pref &pref.Preferences) Builder {
// parse all deps from already parsed files // parse all deps from already parsed files
pub fn (mut b Builder) parse_imports() { pub fn (mut b Builder) parse_imports() {
mut done_imports := []string{} mut done_imports := []string{}
if b.pref.is_script { if b.pref.is_script {
done_imports << 'os' done_imports << 'os'
}
for file in b.parsed_files {
if file.mod.name != 'main' && file.mod.name !in done_imports {
done_imports << file.mod.name
} }
}
// NB: b.parsed_files is appended in the loop, // NB: b.parsed_files is appended in the loop,
// so we can not use the shorter `for in` form. // so we can not use the shorter `for in` form.
for i := 0; i < b.parsed_files.len; i++ { for i := 0; i < b.parsed_files.len; i++ {
@ -244,7 +251,9 @@ fn (b &Builder) show_total_warns_and_errors_stats() {
} }
fn (b &Builder) print_warnings_and_errors() { fn (b &Builder) print_warnings_and_errors() {
defer { b.show_total_warns_and_errors_stats() } defer {
b.show_total_warns_and_errors_stats()
}
if b.pref.output_mode == .silent { if b.pref.output_mode == .silent {
if b.checker.nr_errors > 0 { if b.checker.nr_errors > 0 {
exit(1) exit(1)