Skip to content

Commit f9d21f9

Browse files
committed
fix: redirects to include the original request headers, mainly authorization
1 parent aeb1491 commit f9d21f9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/main/java/com/browserstack/client/BrowserStackRequest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import com.browserstack.client.exception.BrowserStackObjectNotFound;
66
import com.fasterxml.jackson.databind.node.ArrayNode;
77
import com.fasterxml.jackson.databind.node.ObjectNode;
8-
import com.google.api.client.http.HttpContent;
9-
import com.google.api.client.http.HttpRequest;
10-
import com.google.api.client.http.HttpResponse;
11-
import com.google.api.client.http.UrlEncodedContent;
8+
import com.google.api.client.http.*;
129
import com.google.api.client.util.escape.CharEscapers;
1310

1411
import java.io.ByteArrayOutputStream;
@@ -32,6 +29,8 @@ public BrowserStackRequest(HttpRequest httpRequest) {
3229

3330
this.httpRequest = httpRequest;
3431
this.httpRequest.getHeaders().setUserAgent(USER_AGENT);
32+
this.httpRequest.setFollowRedirects(false);
33+
this.httpRequest.setThrowExceptionOnExecuteError(false);
3534
}
3635

3736
private static String getRawBody(InputStream inputStream) throws IOException {
@@ -152,6 +151,11 @@ private HttpResponse execute() throws BrowserStackException, IOException {
152151

153152
case 404:
154153
throw new BrowserStackObjectNotFound(response.parseAsString());
154+
155+
case 302:
156+
String redirectLocation = httpRequest.getResponseHeaders().getLocation();
157+
httpRequest.setUrl(new GenericUrl(httpRequest.getUrl().toURL(redirectLocation)));
158+
response = httpRequest.execute();
155159
}
156160
}
157161

0 commit comments

Comments
 (0)