@@ -128,16 +128,16 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
128
128
method .setRequestHeader (AUTHORIZATION_HEADER , mCredentials .getHeaderAuth ());
129
129
}
130
130
131
+ method .setFollowRedirects (mFollowRedirects );
131
132
status = method .execute ();
132
133
stacklog (status , method );
133
134
134
- if (mConnectionValidator != null &&
135
+ if (!mFollowRedirects &&
136
+ mConnectionValidator != null &&
135
137
(status == HttpConstants .HTTP_MOVED_TEMPORARILY ||
136
138
(!(mCredentials instanceof OwnCloudAnonymousCredentials ) &&
137
139
status == HttpConstants .HTTP_UNAUTHORIZED ))) {
138
140
retry = mConnectionValidator .validate (this , mSingleSessionManager ); // retry on success fail on no success
139
- } else if (mFollowRedirects ) {
140
- status = followRedirection (method ).getLastStatus ();
141
141
}
142
142
143
143
} while (retry && repeatCounter < MAX_RETRY_COUNT );
@@ -167,87 +167,6 @@ private void stacklog(int status, HttpBaseMethod method) {
167
167
}
168
168
}
169
169
170
- private int executeRedirectedHttpMethod (HttpBaseMethod method ) throws Exception {
171
- int status ;
172
- String requestId = RandomUtils .generateRandomUUID ();
173
-
174
- // Header to allow tracing requests in apache and ownCloud logs
175
- Timber .d ("Executing in request with id %s" , requestId );
176
- method .setRequestHeader (OC_X_REQUEST_ID , requestId );
177
- method .setRequestHeader (HttpConstants .USER_AGENT_HEADER , SingleSessionManager .getUserAgent ());
178
- method .setRequestHeader (HttpConstants .ACCEPT_ENCODING_HEADER , HttpConstants .ACCEPT_ENCODING_IDENTITY );
179
- if (mCredentials .getHeaderAuth () != null ) {
180
- method .setRequestHeader (AUTHORIZATION_HEADER , mCredentials .getHeaderAuth ());
181
- }
182
- status = method .execute ();
183
- return status ;
184
- }
185
-
186
- public RedirectionPath followRedirection (HttpBaseMethod method ) throws Exception {
187
- int redirectionsCount = 0 ;
188
- int status = method .getStatusCode ();
189
- RedirectionPath redirectionPath = new RedirectionPath (status , MAX_REDIRECTIONS_COUNT );
190
-
191
- while (redirectionsCount < MAX_REDIRECTIONS_COUNT &&
192
- (status == HttpConstants .HTTP_MOVED_PERMANENTLY ||
193
- status == HttpConstants .HTTP_MOVED_TEMPORARILY ||
194
- status == HttpConstants .HTTP_TEMPORARY_REDIRECT )
195
- ) {
196
-
197
- final String location = method .getResponseHeader (HttpConstants .LOCATION_HEADER ) != null
198
- ? method .getResponseHeader (HttpConstants .LOCATION_HEADER )
199
- : method .getResponseHeader (HttpConstants .LOCATION_HEADER_LOWER );
200
-
201
- if (location != null ) {
202
- Timber .d ("#" + mInstanceNumber + "Location to redirect: " + location );
203
-
204
- redirectionPath .addLocation (location );
205
-
206
- // Release the connection to avoid reach the max number of connections per hostClientManager
207
- // due to it will be set a different url
208
- exhaustResponse (method .getResponseBodyAsStream ());
209
-
210
- Timber .d ("+++++++++++++++++++++++++++++++++++++++ %s" , getFullUrl (location ));
211
- method .setUrl (getFullUrl (location ));
212
- final String destination = method .getRequestHeader ("Destination" ) != null
213
- ? method .getRequestHeader ("Destination" )
214
- : method .getRequestHeader ("destination" );
215
-
216
- if (destination != null ) {
217
- final int suffixIndex = location .lastIndexOf (getUserFilesWebDavUri ().toString ());
218
- final String redirectionBase = location .substring (0 , suffixIndex );
219
- final String destinationPath = destination .substring (mBaseUri .toString ().length ());
220
-
221
- method .setRequestHeader ("destination" , redirectionBase + destinationPath );
222
- }
223
- try {
224
- status = executeRedirectedHttpMethod (method );
225
- } catch (HttpException e ) {
226
- if (e .getMessage ().contains (Integer .toString (HttpConstants .HTTP_MOVED_TEMPORARILY ))) {
227
- status = HttpConstants .HTTP_MOVED_TEMPORARILY ;
228
- } else {
229
- throw e ;
230
- }
231
- }
232
- redirectionPath .addStatus (status );
233
- redirectionsCount ++;
234
-
235
- } else {
236
- Timber .d (" #" + mInstanceNumber + "No location to redirect!" );
237
- status = HttpConstants .HTTP_NOT_FOUND ;
238
- }
239
- }
240
- return redirectionPath ;
241
- }
242
-
243
- private HttpUrl getFullUrl (String redirection ) {
244
- if (redirection .startsWith ("/" )) {
245
- return HttpUrl .parse (mBaseUri .toString () + redirection );
246
- } else {
247
- return HttpUrl .parse (redirection );
248
- }
249
- }
250
-
251
170
/**
252
171
* Exhausts a not interesting HTTP response. Encouraged by HttpClient documentation.
253
172
*
0 commit comments