Skip to content

Commit

Permalink
use http1.1 to boost the upload speed (#564)
Browse files Browse the repository at this point in the history
Co-authored-by: PT-ATA No One <[email protected]>
  • Loading branch information
unglaublicherdude and ata-no-one authored Aug 15, 2024
1 parent 9f806cd commit 72f0527
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 13 additions & 4 deletions golang/vaas/v2/examples/file-verdict-request/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {
if err := godotenv.Load(); err != nil {
log.Printf("failed to load environment - %v", err)
}
log.Printf(os.LookupEnv("CLIENT_ID"))

// Retrieve the Client ID and Client Secret from environment variables
clientID, exists := os.LookupEnv("CLIENT_ID")
Expand All @@ -31,16 +32,24 @@ func main() {
if !exists {
log.Fatal("no Client Secret set")
}
tokenEndpoint, exists := os.LookupEnv("TOKEN_URL")
if !exists {
tokenEndpoint = "https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token"
}
vaasUrl, exists := os.LookupEnv("VAAS_URL")
if !exists {
tokenEndpoint = "wss://gateway.staging.vaas.gdatasecurity.de"
}

// Create a new authenticator with the provided Client ID and Client Secret
auth := authenticator.NewWithDefaultTokenEndpoint(clientID, clientSecret)
auth := authenticator.New(clientID, clientSecret, tokenEndpoint)

// Create a new VaaS client with default options
vaasClient := vaas.NewWithDefaultEndpoint(options.VaasOptions{
vaasClient := vaas.New(options.VaasOptions{
UseHashLookup: true,
UseCache: false,
EnableLogs: false,
})
}, vaasUrl)

// Create a context with a cancellation function
connectCtx, webSocketCancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand All @@ -57,7 +66,7 @@ func main() {
defer analysisCancel()

// Request a verdict for a specific file (replace "path-to-your-file" with the actual file path)
result, err := vaasClient.ForFile(analysisCtx, "path-to-your-file")
result, err := vaasClient.ForFile(analysisCtx, "1GB.testfile")
if err != nil {
log.Fatal(err)
}
Expand Down
12 changes: 11 additions & 1 deletion golang/vaas/v2/pkg/vaas/vaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vaas
import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -576,8 +577,17 @@ func (v *vaas) uploadFile(file io.Reader, contentLength int64, url string, token
}

req.Header.Add("Authorization", token)
log.Println(req.Proto)

This comment has been minimized.

Copy link
@GermanCoding

GermanCoding Aug 15, 2024

Collaborator

There is some debug logging here that we should remove

log.Println(req.ProtoMajor)
log.Println(req.ProtoMinor)

httpResponse, err := http.DefaultClient.Do(req)
client := http.Client{
Transport: &http.Transport{
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
},
}
httpResponse, err := client.Do(req)
log.Println(httpResponse.Proto)
if err != nil {
return err
}
Expand Down

0 comments on commit 72f0527

Please sign in to comment.