[XAPID-1070] reuse the same http client, change maxIdleConnsPerHost
diff --git a/init.go b/init.go index 6384939..1c4e16d 100644 --- a/init.go +++ b/init.go
@@ -21,6 +21,7 @@ "time" "github.com/30x/apid-core" + "net/http" "sync" ) @@ -40,6 +41,9 @@ configDownloadQueueSize = "apigeesync_download_queue_size" configBlobServerBaseURI = "apigeesync_blob_server_base" configStoragePath = "local_storage_path" + maxIdleConnsPerHost = 50 + httpTimeout = time.Minute + configBearerToken = "apigeesync_bearer_token" ) var ( @@ -107,6 +111,18 @@ log.Debug("apiServerBaseURI = " + apiServerBaseURI.String()) + // initialize tracker client + httpClient := &http.Client{ + Transport: &http.Transport{ + MaxIdleConnsPerHost: maxIdleConnsPerHost, + }, + Timeout: httpTimeout, + CheckRedirect: func(req *http.Request, _ []*http.Request) error { + req.Header.Set("Authorization", getBearerToken()) + return nil + }, + } + // initialize db manager dbMan := &dbManager{ @@ -149,9 +165,7 @@ bundleCleanupDelay: bundleCleanupDelay, downloadQueue: make(chan *DownloadRequest, downloadQueueSize), isClosed: new(int32), - client: &http.Client{ - Timeout: bundleDownloadConnTimeout, - }, + client: httpClient, } bundleMan.initializeBundleDownloading() @@ -173,3 +187,7 @@ return pluginData, nil } + +func getBearerToken() string { + return "Bearer " + config.GetString(configBearerToken) +}