@@ -86,15 +86,15 @@ private static String encodeUrlParams(/*@Nullable*/String userLocale,
8686 }
8787
8888 public static List <HttpRequestor .Header > addAuthHeader (/*@Nullable*/ List <HttpRequestor .Header > headers ,
89- String accessToken )
89+ String accessToken )
9090 {
9191 if (headers == null ) headers = new ArrayList <HttpRequestor .Header >();
9292 headers .add (new HttpRequestor .Header ("Authorization" , "Bearer " + accessToken ));
9393 return headers ;
9494 }
9595
9696 public static List <HttpRequestor .Header > addSelectUserHeader (/*@Nullable*/ List <HttpRequestor .Header > headers ,
97- String memberId )
97+ String memberId )
9898 {
9999 if (memberId == null ) throw new IllegalArgumentException ("'memberId' is null" );
100100 if (headers == null ) headers = new ArrayList <HttpRequestor .Header >();
@@ -103,27 +103,32 @@ public static List<HttpRequestor.Header> addSelectUserHeader(/*@Nullable*/List<H
103103 }
104104
105105 public static List <HttpRequestor .Header > addUserAgentHeader (/*@Nullable*/ List <HttpRequestor .Header > headers ,
106- DbxRequestConfig requestConfig )
106+ DbxRequestConfig requestConfig ,
107+ String clientUserAgentIdentifier )
107108 {
108109 if (headers == null ) headers = new ArrayList <HttpRequestor .Header >();
109- headers .add (buildUserAgentHeader (requestConfig ));
110+ headers .add (buildUserAgentHeader (requestConfig , clientUserAgentIdentifier ));
110111 return headers ;
111112 }
112113
113- public static HttpRequestor .Header buildUserAgentHeader (DbxRequestConfig requestConfig )
114+ public static HttpRequestor .Header buildUserAgentHeader (DbxRequestConfig requestConfig , String clientUserAgentIdentifier )
114115 {
115- return new HttpRequestor .Header ("User-Agent" , requestConfig .clientIdentifier + " Dropbox-Java-SDK /" + DbxSdkVersion .Version );
116+ return new HttpRequestor .Header ("User-Agent" , requestConfig .clientIdentifier + " " + clientUserAgentIdentifier + " /" + DbxSdkVersion .Version );
116117 }
117118
118119 /**
119120 * Convenience function for making HTTP GET requests.
120121 */
121- public static HttpRequestor .Response startGet (DbxRequestConfig requestConfig , String accessToken , String host , String path ,
122+ public static HttpRequestor .Response startGet (DbxRequestConfig requestConfig ,
123+ String accessToken ,
124+ String clientUserAgentIdentifier ,
125+ String host ,
126+ String path ,
122127 /*@Nullable*/ String /*@Nullable*/ [] params ,
123128 /*@Nullable*/ List <HttpRequestor .Header > headers )
124129 throws DbxException .NetworkIO
125130 {
126- headers = addUserAgentHeader (headers , requestConfig );
131+ headers = addUserAgentHeader (headers , requestConfig , clientUserAgentIdentifier );
127132 headers = addAuthHeader (headers , accessToken );
128133
129134 String url = buildUrlWithParams (requestConfig .userLocale , host , path , params );
@@ -138,13 +143,15 @@ public static HttpRequestor.Response startGet(DbxRequestConfig requestConfig, St
138143 /**
139144 * Convenience function for making HTTP PUT requests.
140145 */
141- public static HttpRequestor .Uploader startPut (DbxRequestConfig requestConfig , String accessToken ,
146+ public static HttpRequestor .Uploader startPut (DbxRequestConfig requestConfig ,
147+ String accessToken ,
148+ String clientUserAgentIdentifier ,
142149 String host , String path ,
143150 /*@Nullable*/ String /*@Nullable*/ [] params ,
144151 /*@Nullable*/ List <HttpRequestor .Header > headers )
145152 throws DbxException .NetworkIO
146153 {
147- headers = addUserAgentHeader (headers , requestConfig );
154+ headers = addUserAgentHeader (headers , requestConfig , clientUserAgentIdentifier );
148155 headers = addAuthHeader (headers , accessToken );
149156
150157 String url = buildUrlWithParams (requestConfig .userLocale , host , path , params );
@@ -159,7 +166,9 @@ public static HttpRequestor.Uploader startPut(DbxRequestConfig requestConfig, St
159166 /**
160167 * Convenience function for making HTTP POST requests.
161168 */
162- public static HttpRequestor .Response startPostNoAuth (DbxRequestConfig requestConfig , String host ,
169+ public static HttpRequestor .Response startPostNoAuth (DbxRequestConfig requestConfig ,
170+ String clientUserAgentIdentifier ,
171+ String host ,
163172 String path ,
164173 /*@Nullable*/ String /*@Nullable*/ [] params ,
165174 /*@Nullable*/ List <HttpRequestor .Header > headers )
@@ -170,21 +179,24 @@ public static HttpRequestor.Response startPostNoAuth(DbxRequestConfig requestCon
170179 if (headers == null ) headers = new ArrayList <HttpRequestor .Header >();
171180 headers .add (new HttpRequestor .Header ("Content-Type" , "application/x-www-form-urlencoded; charset=utf-8" ));
172181
173- return startPostRaw (requestConfig , host , path , encodedParams , headers );
182+ return startPostRaw (requestConfig , clientUserAgentIdentifier , host , path , encodedParams , headers );
174183 }
175184
185+
176186 /**
177187 * Convenience function for making HTTP POST requests. Like startPostNoAuth but takes byte[] instead of params.
178188 */
179- public static HttpRequestor .Response startPostRaw (DbxRequestConfig requestConfig , String host ,
189+ public static HttpRequestor .Response startPostRaw (DbxRequestConfig requestConfig ,
190+ String clientUserAgentIdentifier ,
191+ String host ,
180192 String path ,
181193 byte [] body ,
182194 /*@Nullable*/ List <HttpRequestor .Header > headers )
183195 throws DbxException .NetworkIO
184196 {
185197 String uri = buildUri (host , path );
186198
187- headers = addUserAgentHeader (headers , requestConfig );
199+ headers = addUserAgentHeader (headers , requestConfig , clientUserAgentIdentifier );
188200 headers .add (new HttpRequestor .Header ("Content-Length" , Integer .toString (body .length )));
189201
190202 try {
@@ -345,13 +357,17 @@ public static abstract class ResponseHandler<T>
345357 public abstract T handle (HttpRequestor .Response response ) throws DbxException ;
346358 }
347359
348- public static <T > T doGet (DbxRequestConfig requestConfig , String accessToken , String host , String path ,
360+ public static <T > T doGet (DbxRequestConfig requestConfig ,
361+ String accessToken ,
362+ String clientUserAgentIdentifier ,
363+ String host ,
364+ String path ,
349365 /*@Nullable*/ String /*@Nullable*/ [] params ,
350366 /*@Nullable*/ List <HttpRequestor .Header > headers ,
351367 ResponseHandler <T > handler )
352368 throws DbxException
353369 {
354- HttpRequestor .Response response = startGet (requestConfig , accessToken , host , path , params , headers );
370+ HttpRequestor .Response response = startGet (requestConfig , accessToken , clientUserAgentIdentifier , host , path , params , headers );
355371 try {
356372 return handler .handle (response );
357373 }
@@ -366,23 +382,30 @@ public static <T> T doGet(DbxRequestConfig requestConfig, String accessToken, St
366382 }
367383 }
368384
369- public static <T > T doPost (DbxRequestConfig requestConfig , String accessToken , String host , String path ,
385+ public static <T > T doPost (DbxRequestConfig requestConfig ,
386+ String accessToken ,
387+ String clientUserAgentIdentifier ,
388+ String host ,
389+ String path ,
370390 /*@Nullable*/ String /*@Nullable*/ [] params ,
371391 /*@Nullable*/ List <HttpRequestor .Header > headers ,
372392 ResponseHandler <T > handler )
373393 throws DbxException
374394 {
375395 headers = addAuthHeader (headers , accessToken );
376- return doPostNoAuth (requestConfig , host , path , params , headers , handler );
396+ return doPostNoAuth (requestConfig , clientUserAgentIdentifier , host , path , params , headers , handler );
377397 }
378398
379- public static <T > T doPostNoAuth (DbxRequestConfig requestConfig , String host , String path ,
399+ public static <T > T doPostNoAuth (DbxRequestConfig requestConfig ,
400+ String clientUserAgentIdentifier ,
401+ String host ,
402+ String path ,
380403 /*@Nullable*/ String /*@Nullable*/ [] params ,
381404 /*@Nullable*/ List <HttpRequestor .Header > headers ,
382405 ResponseHandler <T > handler )
383406 throws DbxException
384407 {
385- HttpRequestor .Response response = startPostNoAuth (requestConfig , host , path , params , headers );
408+ HttpRequestor .Response response = startPostNoAuth (requestConfig , clientUserAgentIdentifier , host , path , params , headers );
386409 return finishResponse (response , handler );
387410 }
388411
0 commit comments