@@ -124,7 +124,6 @@ class NextcloudClient private constructor(
124124 }
125125
126126 @Throws(IOException ::class )
127- @Suppress(" NestedBlockDepth" )
128127 fun followRedirection (method : OkHttpMethodBase ): RedirectionPath {
129128 var redirectionsCount = 0
130129 var status = method.getStatusCode()
@@ -144,22 +143,11 @@ class NextcloudClient private constructor(
144143 // due to it will be set a different url
145144 method.releaseConnection()
146145 method.uri = location
147- var destination = method.getRequestHeader(" Destination" )
146+ val destination = method.getRequestHeader(" Destination" )
148147 ? : method.getRequestHeader(" destination" )
149148
150149 if (destination != null ) {
151- val suffixIndex = location.lastIndexOf(AccountUtils .WEBDAV_PATH_9_0 )
152- val redirectionBase = location.substring(0 , suffixIndex)
153- val destinationStr = destination
154- val destinationPath = destinationStr.substring(baseUri.toString().length)
155- val redirectedDestination = redirectionBase + destinationPath
156- destination = redirectedDestination
157-
158- if (method.getRequestHeader(" Destination" ).isNullOrEmpty()) {
159- method.addRequestHeader(" destination" , destination)
160- } else {
161- method.addRequestHeader(" Destination" , destination)
162- }
150+ setRedirectedDestinationHeader(method, location, destination)
163151 }
164152
165153 status = method.execute(this )
@@ -174,6 +162,23 @@ class NextcloudClient private constructor(
174162 return result
175163 }
176164
165+ private fun setRedirectedDestinationHeader (
166+ method : OkHttpMethodBase ,
167+ location : String ,
168+ destination : String
169+ ) {
170+ val suffixIndex = location.lastIndexOf(AccountUtils .WEBDAV_PATH_9_0 )
171+ val redirectionBase = location.substring(0 , suffixIndex)
172+ val destinationPath = destination.substring(baseUri.toString().length)
173+ val redirectedDestination = redirectionBase + destinationPath
174+
175+ if (method.getRequestHeader(" Destination" ).isNullOrEmpty()) {
176+ method.addRequestHeader(" destination" , redirectedDestination)
177+ } else {
178+ method.addRequestHeader(" Destination" , redirectedDestination)
179+ }
180+ }
181+
177182 fun getUserIdEncoded (): String {
178183 return delegate.userIdEncoded!!
179184 }
0 commit comments