@@ -184,6 +184,41 @@ func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{})
184
184
})
185
185
}
186
186
187
+ // authHeaders ensures the given map contains a REST auth header
188
+ func (c * Client ) authHeaders (h map [string ]string ) map [string ]string {
189
+ if _ , exists := h [internal .SessionCookieName ]; exists {
190
+ return h
191
+ }
192
+ if h == nil {
193
+ h = make (map [string ]string )
194
+ }
195
+
196
+ h [internal .SessionCookieName ] = c .SessionID ()
197
+
198
+ return h
199
+ }
200
+
201
+ // Download wraps soap.Client.Download, adding the REST authentication header
202
+ func (c * Client ) Download (ctx context.Context , u * url.URL , param * soap.Download ) (io.ReadCloser , int64 , error ) {
203
+ p := * param
204
+ p .Headers = c .authHeaders (p .Headers )
205
+ return c .Client .Download (ctx , u , & p )
206
+ }
207
+
208
+ // DownloadFile wraps soap.Client.DownloadFile, adding the REST authentication header
209
+ func (c * Client ) DownloadFile (ctx context.Context , file string , u * url.URL , param * soap.Download ) error {
210
+ p := * param
211
+ p .Headers = c .authHeaders (p .Headers )
212
+ return c .Client .DownloadFile (ctx , file , u , & p )
213
+ }
214
+
215
+ // Upload wraps soap.Client.Upload, adding the REST authentication header
216
+ func (c * Client ) Upload (ctx context.Context , f io.Reader , u * url.URL , param * soap.Upload ) error {
217
+ p := * param
218
+ p .Headers = c .authHeaders (p .Headers )
219
+ return c .Client .Upload (ctx , f , u , & p )
220
+ }
221
+
187
222
// Login creates a new session via Basic Authentication with the given url.Userinfo.
188
223
func (c * Client ) Login (ctx context.Context , user * url.Userinfo ) error {
189
224
req := c .Resource (internal .SessionPath ).Request (http .MethodPost )
0 commit comments