examples/client: Stream response body
This commit is contained in:
parent
9974071657
commit
31e16d5a4c
@ -97,7 +97,8 @@ func do(req *gemini.Request, via []*gemini.Request) (*gemini.Response, error) {
|
|||||||
client := gemini.Client{
|
client := gemini.Client{
|
||||||
TrustCertificate: trustCertificate,
|
TrustCertificate: trustCertificate,
|
||||||
}
|
}
|
||||||
resp, err := client.Do(context.Background(), req)
|
ctx := context.Background()
|
||||||
|
resp, err := client.Do(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
@ -156,11 +157,10 @@ func main() {
|
|||||||
|
|
||||||
// Handle response
|
// Handle response
|
||||||
if resp.Status.Class() == gemini.StatusSuccess {
|
if resp.Status.Class() == gemini.StatusSuccess {
|
||||||
body, err := io.ReadAll(resp.Body)
|
_, err := io.Copy(os.Stdout, resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
fmt.Print(string(body))
|
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%d %s\n", resp.Status, resp.Meta)
|
fmt.Printf("%d %s\n", resp.Status, resp.Meta)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user