Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / github.com / Azure / go-autorest / autorest / adal / sender.go
1 package adal
2
3 // Copyright 2017 Microsoft Corporation
4 //
5 //  Licensed under the Apache License, Version 2.0 (the "License");
6 //  you may not use this file except in compliance with the License.
7 //  You may obtain a copy of the License at
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
11 //  Unless required by applicable law or agreed to in writing, software
12 //  distributed under the License is distributed on an "AS IS" BASIS,
13 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 //  See the License for the specific language governing permissions and
15 //  limitations under the License.
16
17 import (
18         "net/http"
19 )
20
21 const (
22         contentType      = "Content-Type"
23         mimeTypeFormPost = "application/x-www-form-urlencoded"
24 )
25
26 // Sender is the interface that wraps the Do method to send HTTP requests.
27 //
28 // The standard http.Client conforms to this interface.
29 type Sender interface {
30         Do(*http.Request) (*http.Response, error)
31 }
32
33 // SenderFunc is a method that implements the Sender interface.
34 type SenderFunc func(*http.Request) (*http.Response, error)
35
36 // Do implements the Sender interface on SenderFunc.
37 func (sf SenderFunc) Do(r *http.Request) (*http.Response, error) {
38         return sf(r)
39 }
40
41 // SendDecorator takes and possibly decorates, by wrapping, a Sender. Decorators may affect the
42 // http.Request and pass it along or, first, pass the http.Request along then react to the
43 // http.Response result.
44 type SendDecorator func(Sender) Sender
45
46 // CreateSender creates, decorates, and returns, as a Sender, the default http.Client.
47 func CreateSender(decorators ...SendDecorator) Sender {
48         return DecorateSender(&http.Client{}, decorators...)
49 }
50
51 // DecorateSender accepts a Sender and a, possibly empty, set of SendDecorators, which is applies to
52 // the Sender. Decorators are applied in the order received, but their affect upon the request
53 // depends on whether they are a pre-decorator (change the http.Request and then pass it along) or a
54 // post-decorator (pass the http.Request along and react to the results in http.Response).
55 func DecorateSender(s Sender, decorators ...SendDecorator) Sender {
56         for _, decorate := range decorators {
57                 s = decorate(s)
58         }
59         return s
60 }