transferRequest downloads the requested resource from the request URL
(requestURL string, log *zerolog.Logger)
| 116 | |
| 117 | // transferRequest downloads the requested resource from the request URL |
| 118 | func transferRequest(requestURL string, log *zerolog.Logger) ([]byte, string, error) { |
| 119 | client := &http.Client{Timeout: clientTimeout} |
| 120 | const pollAttempts = 10 |
| 121 | // we do "long polling" on the endpoint to get the resource. |
| 122 | for i := 0; i < pollAttempts; i++ { |
| 123 | buf, key, err := poll(client, requestURL, log) |
| 124 | if err != nil { |
| 125 | return nil, "", err |
| 126 | } else if len(buf) > 0 { |
| 127 | return buf, key, nil |
| 128 | } |
| 129 | } |
| 130 | return nil, "", errors.New("Failed to fetch resource") |
| 131 | } |
| 132 | |
| 133 | // poll the endpoint for the request resource, waiting for the user interaction |
| 134 | func poll(client *http.Client, requestURL string, log *zerolog.Logger) ([]byte, string, error) { |