From 1f0338a80da59ff222e254263e8a72f608a43456 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 18 Nov 2022 17:31:12 +0530 Subject: [PATCH] Use http client from msgraphcore (#1484) ## Description Use http client from msgraphcore instead of the one from net/http as it has preconfigured middleware. ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [x] :hamster: Trivial/Minor ## Issue(s) * https://github.com/alcionai/corso/issues/581 ## Test Plan - [ ] :muscle: Manual - [ ] :zap: Unit test - [x] :green_heart: E2E --- src/internal/connector/onedrive/item.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index 7ec9e1e41..2f03f97d3 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -3,9 +3,10 @@ package onedrive import ( "context" "io" - "net/http" "time" + msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go" + msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core" msup "github.com/microsoftgraph/msgraph-sdk-go/drives/item/items/item/createuploadsession" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/pkg/errors" @@ -51,9 +52,13 @@ func driveItemReader( downloadURL := item.GetAdditionalData()[downloadURLKey].(*string) - // TODO: We should use the `msgraphgocore` http client which has the right - // middleware/options configured - resp, err := http.Get(*downloadURL) + clientOptions := msgraphsdk.GetDefaultClientOptions() + middlewares := msgraphgocore.GetDefaultMiddlewaresWithOptions(&clientOptions) + + httpClient := msgraphgocore.GetDefaultClient(&clientOptions, middlewares...) + httpClient.Timeout = 0 // need infinite timeout for pulling large files + + resp, err := httpClient.Get(*downloadURL) if err != nil { return nil, nil, errors.Wrapf(err, "failed to download file from %s", *downloadURL) }