Skip to content

Commit 6e5a602

Browse files
committed
Remove redirect processing that never worked
1 parent 1c42d15 commit 6e5a602

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

restapi/api_client.go

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type api_client struct {
4141
username string
4242
password string
4343
headers map[string]string
44-
redirects int
4544
use_cookie bool
4645
timeout int
4746
id_attribute string
@@ -122,7 +121,6 @@ func NewAPIClient(opt *apiClientOpt) (*api_client, error) {
122121
create_returns_object: opt.create_returns_object,
123122
xssi_prefix: opt.xssi_prefix,
124123
debug: opt.debug,
125-
redirects: 5,
126124
}
127125

128126
if opt.debug {
@@ -153,8 +151,7 @@ func (obj *api_client) toString() string {
153151
}
154152

155153
/* Helper function that handles sending/receiving and handling
156-
of HTTP data in and out.
157-
TODO: Handle redirects */
154+
of HTTP data in and out. */
158155
func (client *api_client) send_request(method string, path string, data string) (string, error) {
159156
full_uri := client.uri + path
160157
var req *http.Request
@@ -214,45 +211,38 @@ func (client *api_client) send_request(method string, path string, data string)
214211
log.Printf("%s\n", body)
215212
}
216213

217-
for num_redirects := client.redirects; num_redirects >= 0; num_redirects-- {
218-
resp, err := client.http_client.Do(req)
214+
resp, err := client.http_client.Do(req)
219215

220-
if err != nil {
221-
//log.Printf("api_client.go: Error detected: %s\n", err)
222-
return "", err
223-
}
216+
if err != nil {
217+
//log.Printf("api_client.go: Error detected: %s\n", err)
218+
return "", err
219+
}
224220

225-
if client.debug {
226-
log.Printf("api_client.go: Response code: %d\n", resp.StatusCode)
227-
log.Printf("api_client.go: Response headers:\n")
228-
for name, headers := range resp.Header {
229-
for _, h := range headers {
230-
log.Printf("api_client.go: %v: %v", name, h)
231-
}
221+
if client.debug {
222+
log.Printf("api_client.go: Response code: %d\n", resp.StatusCode)
223+
log.Printf("api_client.go: Response headers:\n")
224+
for name, headers := range resp.Header {
225+
for _, h := range headers {
226+
log.Printf("api_client.go: %v: %v", name, h)
232227
}
233228
}
229+
}
234230

235-
bodyBytes, err2 := ioutil.ReadAll(resp.Body)
236-
resp.Body.Close()
231+
bodyBytes, err2 := ioutil.ReadAll(resp.Body)
232+
resp.Body.Close()
237233

238-
if err2 != nil {
239-
return "", err2
240-
}
241-
body := strings.TrimPrefix(string(bodyBytes), client.xssi_prefix)
242-
243-
if resp.StatusCode == 301 || resp.StatusCode == 302 {
244-
//Redirecting... decrement num_redirects and proceed to the next loop
245-
//uri = URI.parse(rsp['Location'])
246-
} else if resp.StatusCode == 404 || resp.StatusCode < 200 || resp.StatusCode >= 303 {
247-
return "", errors.New(fmt.Sprintf("Unexpected response code '%d': %s", resp.StatusCode, body))
248-
} else {
249-
if client.debug {
250-
log.Printf("api_client.go: BODY:\n%s\n", body)
251-
}
252-
return body, nil
253-
}
234+
if err2 != nil {
235+
return "", err2
236+
}
237+
body := strings.TrimPrefix(string(bodyBytes), client.xssi_prefix)
238+
if client.debug {
239+
log.Printf("api_client.go: BODY:\n%s\n", body)
240+
}
241+
242+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
243+
return body, errors.New(fmt.Sprintf("Unexpected response code '%d': %s", resp.StatusCode, body))
244+
}
254245

255-
} //End loop through redirect attempts
246+
return body, nil
256247

257-
return "", errors.New("Error - too many redirects!")
258248
}

0 commit comments

Comments
 (0)