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

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🐹 Trivial/Minor

## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* https://github.com/alcionai/corso/issues/581

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [ ]  Unit test
- [x] 💚 E2E
This commit is contained in:
Abin Simon 2022-11-18 17:31:12 +05:30 committed by GitHub
parent f114785ebb
commit 1f0338a80d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}