@@ -46,6 +46,7 @@ public class BoxAPIRequest {
4646 private long bodyLength ;
4747 private Map <String , List <String >> requestProperties ;
4848 private int numRedirects ;
49+ private boolean shouldAuthenticate ;
4950
5051 /**
5152 * Constructs an unauthenticated BoxAPIRequest.
@@ -68,6 +69,7 @@ public BoxAPIRequest(BoxAPIConnection api, URL url, String method) {
6869 this .method = method ;
6970 this .headers = new ArrayList <RequestHeader >();
7071 this .backoffCounter = new BackoffCounter (new Time ());
72+ this .shouldAuthenticate = true ;
7173
7274 this .addHeader ("Accept-Encoding" , "gzip" );
7375 this .addHeader ("Accept-Charset" , "utf-8" );
@@ -347,7 +349,9 @@ private BoxAPIResponse trySend(ProgressListener listener) {
347349 }
348350
349351 if (this .api != null ) {
350- connection .addRequestProperty ("Authorization" , "Bearer " + this .api .lockAccessToken ());
352+ if (this .shouldAuthenticate ) {
353+ connection .addRequestProperty ("Authorization" , "Bearer " + this .api .lockAccessToken ());
354+ }
351355 connection .setRequestProperty ("User-Agent" , this .api .getUserAgent ());
352356 if (this .api .getProxy () != null ) {
353357 if (this .api .getProxyUsername () != null && this .api .getProxyPassword () != null ) {
@@ -393,7 +397,7 @@ private BoxAPIResponse trySend(ProgressListener listener) {
393397 throw new BoxAPIException ("Couldn't connect to the Box API due to a network error." , e );
394398 }
395399 } finally {
396- if (this .api != null ) {
400+ if (this .api != null && this . shouldAuthenticate ) {
397401 this .api .unlockAccessToken ();
398402 }
399403 }
@@ -483,6 +487,10 @@ private HttpURLConnection createConnection() {
483487 return connection ;
484488 }
485489
490+ void shouldAuthenticate (boolean shouldAuthenticate ) {
491+ this .shouldAuthenticate = shouldAuthenticate ;
492+ }
493+
486494 private static boolean isResponseRetryable (int responseCode ) {
487495 return (responseCode >= 500 || responseCode == 429 );
488496 }
0 commit comments