1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

net.http: implement a Request.allow_redirect field (true by default) (#13259)

This commit is contained in:
ZoaR 2022-01-24 20:00:30 +08:00 committed by GitHub
parent 3bfad1b943
commit 4ba9a2ffbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,6 +33,7 @@ pub mut:
cert string cert string
cert_key string cert_key string
in_memory_verification bool // if true, verify, cert, and cert_key are read from memory, not from a file in_memory_verification bool // if true, verify, cert, and cert_key are read from memory, not from a file
allow_redirect bool = true //whether to allow redirect
} }
fn (mut req Request) free() { fn (mut req Request) free() {
@ -63,6 +64,9 @@ pub fn (req &Request) do() ?Response {
} }
qresp := req.method_and_url_to_response(req.method, rurl) ? qresp := req.method_and_url_to_response(req.method, rurl) ?
resp = qresp resp = qresp
if !req.allow_redirect {
break
}
if resp.status() !in [.moved_permanently, .found, .see_other, .temporary_redirect, if resp.status() !in [.moved_permanently, .found, .see_other, .temporary_redirect,
.permanent_redirect] { .permanent_redirect] {
break break