Skip to content

Commit

Permalink
Merge pull request #141 from microsoftgraph/feature/references-update
Browse files Browse the repository at this point in the history
- updates references to core libs for multi-valued headers
  • Loading branch information
baywet authored Dec 14, 2022
2 parents 65a86c5 + 2f574f6 commit b9d7e2d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.31.0] - 2022-12-13

### Changed

- Updated references to core libraries for multi-valued request headers.

## [0.30.1] - 2022-10-21

### Changed
Expand Down
4 changes: 3 additions & 1 deletion batch_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ func getRequestInfo() *abstractions.RequestInformation {
reqInfo.SetUri(url.URL{})
reqInfo.Content = []byte(content)
reqInfo.UrlTemplate = "{+baseurl}/$batch"
reqInfo.Headers = map[string]string{"content-type": "application/json"}
headers := abstractions.NewRequestHeaders()
headers.Add("Content-Type", "application/json")
reqInfo.Headers.AddAll(headers)

return reqInfo
}
Expand Down
11 changes: 7 additions & 4 deletions batch_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ func toBatchItem(requestInfo abstractions.RequestInformation) (BatchItem, error)
request.SetId(&newID)
request.SetMethod(&method)
request.SetBody(body)
request.SetHeaders(requestInfo.Headers)
headers := make(map[string]string)
for _, key := range requestInfo.Headers.ListKeys() {
value := requestInfo.Headers.Get(key)
headers[key] = strings.Join(value, ",")
}
request.SetHeaders(headers)
request.SetUrl(&uri.Path)

return request, nil
Expand Down Expand Up @@ -162,9 +167,7 @@ func buildRequestInfo(ctx context.Context, adapter abstractions.RequestAdapter,
if err != nil {
return nil, err
}
requestInfo.Headers = map[string]string{
"Content-Type": "application/json",
}
requestInfo.Headers.Add("Content-Type", "application/json")

return requestInfo, nil
}
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ go 1.18

require (
github.com/google/uuid v1.3.0
github.com/microsoft/kiota-abstractions-go v0.14.0
github.com/microsoft/kiota-http-go v0.9.0
github.com/microsoft/kiota-abstractions-go v0.15.0
github.com/microsoft/kiota-http-go v0.10.0
github.com/microsoft/kiota-serialization-json-go v0.7.2
github.com/stretchr/testify v1.8.1
)

require (
github.com/cjlapao/common-go v0.0.29 // indirect
github.com/cjlapao/common-go v0.0.36 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.opentelemetry.io/otel v1.11.2 // indirect
go.opentelemetry.io/otel/trace v1.11.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
22 changes: 10 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
github.com/cjlapao/common-go v0.0.29 h1:SOiTEEmA/YWOaP37U8beyqbxjvTtWcUAuvQAchGOQLE=
github.com/cjlapao/common-go v0.0.29/go.mod h1:OyTAY388jfEj8uaRzx0uYneFghKDLL5KP+ewSydlQ5g=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cjlapao/common-go v0.0.36 h1:5KvHs+1H4UOAAfZ8MFSA3DALo4JftAOixLq95SZxVUQ=
github.com/cjlapao/common-go v0.0.36/go.mod h1:M3dzazLjTjEtZJbbxoA5ZDiGCiHmpwqW9l4UWaddwOA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -14,11 +13,10 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/microsoft/kiota-abstractions-go v0.14.0 h1:TCYk1+CoBFNhTefKu8OTky4w4HnOoD72EJOeTsTNml8=
github.com/microsoft/kiota-abstractions-go v0.14.0/go.mod h1:/zQPz5M7868/bbN8D4tZHhnOE23Tcc/JBKSNwljOch4=
github.com/microsoft/kiota-http-go v0.9.0 h1:q/JZpWOvHFbxrOjbd8pbODuTx4dlcLahTemM48di/y8=
github.com/microsoft/kiota-http-go v0.9.0/go.mod h1:F652dnY3jVNmwSk46qHXt+HeEbxLkbbn3dUi3lSLHws=
github.com/microsoft/kiota-abstractions-go v0.15.0 h1:NjJvIchKPJCxuVCKzfv28bxRkW+djpnlkcdphsOriKY=
github.com/microsoft/kiota-abstractions-go v0.15.0/go.mod h1:YqOu8G6bZTG0eCIWrmEny8PaF750uaw7tLFac4psf+4=
github.com/microsoft/kiota-http-go v0.10.0 h1:hJwIMkZqgPwRsoZfV5hC4O2OeMvPEZDuhTcyI7Xx3IM=
github.com/microsoft/kiota-http-go v0.10.0/go.mod h1:qr6x7O4SkEJiFVtnlwvNXapwmtJ85ifAiuqOYkKc7hY=
github.com/microsoft/kiota-serialization-json-go v0.7.2 h1:DSb4fNDi5O+DqJwrHo+vRy2kSvfxG5VtN6m1EHzn5Vw=
github.com/microsoft/kiota-serialization-json-go v0.7.2/go.mod h1:Ojum5prlijopyCOZ2XctRcVlE2pU8h+43r3tMdiWoDU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -32,10 +30,10 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4=
go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
go.opentelemetry.io/otel/trace v1.11.1 h1:ofxdnzsNrGBYXbP7t7zpUK281+go5rF7dvdIZXF8gdQ=
go.opentelemetry.io/otel/trace v1.11.1/go.mod h1:f/Q9G7vzk5u91PhbmKbg1Qn0rzH1LJ4vbPHFGkTPtOk=
go.opentelemetry.io/otel v1.11.2 h1:YBZcQlsVekzFsFbjygXMOXSs6pialIZxcjfO/mBDmR0=
go.opentelemetry.io/otel v1.11.2/go.mod h1:7p4EUV+AqgdlNV9gL97IgUZiVR3yrFXYo53f9BM3tRI=
go.opentelemetry.io/otel/trace v1.11.2 h1:Xf7hWSF2Glv0DE3MH7fBHvtpSBsjcBUe5MYAmZM/+y0=
go.opentelemetry.io/otel/trace v1.11.2/go.mod h1:4N+yC7QEz7TTsG9BSRLNAa63eg5E06ObSbKPmxQ/pKA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
8 changes: 4 additions & 4 deletions page_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type PageIterator struct {
reqAdapter abstractions.RequestAdapter
pauseIndex int
constructorFunc serialization.ParsableFactory
headers map[string]string
headers *abstractions.RequestHeaders
reqOptions []abstractions.RequestOption
}

Expand Down Expand Up @@ -62,7 +62,7 @@ func NewPageIterator(res interface{}, reqAdapter abstractions.RequestAdapter, co
reqAdapter: reqAdapter,
pauseIndex: 0,
constructorFunc: constructorFunc,
headers: map[string]string{},
headers: abstractions.NewRequestHeaders(),
}, nil
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func (pI *PageIterator) Iterate(context context.Context, callback func(pageItem
// SetHeaders provides headers for requests made to get subsequent pages
//
// Headers in the initial request -- request to get the first page -- are not included in subsequent page requests.
func (pI *PageIterator) SetHeaders(headers map[string]string) {
func (pI *PageIterator) SetHeaders(headers *abstractions.RequestHeaders) {
pI.headers = headers
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func (pI *PageIterator) fetchNextPage(context context.Context) (serialization.Pa
requestInfo := abstractions.NewRequestInformation()
requestInfo.Method = abstractions.GET
requestInfo.SetUri(*nextLink)
requestInfo.Headers = pI.headers
requestInfo.Headers.AddAll(pI.headers)
requestInfo.AddRequestOptions(pI.reqOptions)

graphResponse, err = pI.reqAdapter.SendAsync(context, requestInfo, pI.constructorFunc, nil)
Expand Down
4 changes: 3 additions & 1 deletion page_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func TestIterateStopsWhenCallbackReturnsFalse(t *testing.T) {
}))
defer testServer.Close()
pageIterator, _ := NewPageIterator(graphResponse, reqAdapter, ParsableCons)
pageIterator.SetHeaders(map[string]string{"ConsistencyLevel": "eventual"})
headers := abstractions.NewRequestHeaders()
headers.Add("ConsistencyLevel", "eventual")
pageIterator.SetHeaders(headers)

pageIterator.Iterate(context.Background(), func(pageItem interface{}) bool {
item := pageItem.(internal.User)
Expand Down

0 comments on commit b9d7e2d

Please sign in to comment.