Loading src/main/java/at/bitfire/dav4android/DavResource.kt +2 −8 Original line number Diff line number Diff line Loading @@ -59,15 +59,9 @@ open class DavResource @JvmOverloads constructor( /** * The resource name (the last segment of the URL path). * * @return resource name or `` (empty string) if the URL ends with a slash * (i.e. the resource is a collection). * Gets the file name of this resource. See [HttpUtils.fileName] for details. */ fun fileName(): String { val pathSegments = location.pathSegments() return pathSegments[pathSegments.size - 1] } fun fileName() = HttpUtils.fileName(location) /** Loading src/main/java/at/bitfire/dav4android/DavResponse.kt +5 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,11 @@ class DavResponse private constructor( body?.close() } /** * Gets the file name of this resource. See [HttpUtils.fileName] for details. */ fun fileName() = HttpUtils.fileName(url) /** * Convenience method to get a certain property from the current response. Does't take * members or related resources into consideration. Loading src/main/java/at/bitfire/dav4android/HttpUtils.kt +12 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ package at.bitfire.dav4android import okhttp3.HttpUrl import okhttp3.Response import java.util.* import java.util.regex.Pattern Loading @@ -14,6 +15,17 @@ object HttpUtils { private val authSchemeWithParam = Pattern.compile("^([^ \"]+) +(.*)$") /** * Gets the resource name (the last segment of the path) from an URL. * * @return resource name or `` (empty string) if the URL ends with a slash * (i.e. the resource is a collection). */ fun fileName(url: HttpUrl): String { val pathSegments = url.pathSegments() return pathSegments[pathSegments.size - 1] } fun listHeader(response: Response, name: String): Array<String> { val value = response.headers(name).joinToString(",") return value.split(',').filter { it.isNotEmpty() }.toTypedArray() Loading src/test/java/at/bitfire/dav4android/DavResourceTest.kt +0 −9 Original line number Diff line number Diff line Loading @@ -47,15 +47,6 @@ class DavResourceTest { private fun sampleUrl() = mockServer.url("/dav/") @Test fun testFilename() { assertEquals("", DavResource(httpClient, sampleUrl().resolve("/")!!).fileName()) assertEquals("hier1", DavResource(httpClient, sampleUrl().resolve("/hier1")!!).fileName()) assertEquals("", DavResource(httpClient, sampleUrl().resolve("/hier1/")!!).fileName()) assertEquals("hier2", DavResource(httpClient, sampleUrl().resolve("/hier1/hier2")!!).fileName()) assertEquals("", DavResource(httpClient, sampleUrl().resolve("/hier1/hier2/")!!).fileName()) } @Test fun testOptions() { val url = sampleUrl() Loading src/test/java/at/bitfire/dav4android/HttpUtilsTest.kt +11 −0 Original line number Diff line number Diff line Loading @@ -6,11 +6,22 @@ package at.bitfire.dav4android import okhttp3.HttpUrl import org.junit.Assert.assertEquals import org.junit.Test class HttpUtilsTest { @Test fun testFilename() { val sampleUrl = HttpUrl.parse("https://example.com")!! assertEquals("", HttpUtils.fileName(sampleUrl.resolve("/")!!)) assertEquals("hier1", HttpUtils.fileName(sampleUrl.resolve("/hier1")!!)) assertEquals("", HttpUtils.fileName(sampleUrl.resolve("/hier1/")!!)) assertEquals("hier2", HttpUtils.fileName(sampleUrl.resolve("/hier2")!!)) assertEquals("", HttpUtils.fileName(sampleUrl.resolve("/hier2/")!!)) } @Test fun testParseWwwAuthenticate() { // two schemes: one without param (illegal!), second with two params Loading Loading
src/main/java/at/bitfire/dav4android/DavResource.kt +2 −8 Original line number Diff line number Diff line Loading @@ -59,15 +59,9 @@ open class DavResource @JvmOverloads constructor( /** * The resource name (the last segment of the URL path). * * @return resource name or `` (empty string) if the URL ends with a slash * (i.e. the resource is a collection). * Gets the file name of this resource. See [HttpUtils.fileName] for details. */ fun fileName(): String { val pathSegments = location.pathSegments() return pathSegments[pathSegments.size - 1] } fun fileName() = HttpUtils.fileName(location) /** Loading
src/main/java/at/bitfire/dav4android/DavResponse.kt +5 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,11 @@ class DavResponse private constructor( body?.close() } /** * Gets the file name of this resource. See [HttpUtils.fileName] for details. */ fun fileName() = HttpUtils.fileName(url) /** * Convenience method to get a certain property from the current response. Does't take * members or related resources into consideration. Loading
src/main/java/at/bitfire/dav4android/HttpUtils.kt +12 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ package at.bitfire.dav4android import okhttp3.HttpUrl import okhttp3.Response import java.util.* import java.util.regex.Pattern Loading @@ -14,6 +15,17 @@ object HttpUtils { private val authSchemeWithParam = Pattern.compile("^([^ \"]+) +(.*)$") /** * Gets the resource name (the last segment of the path) from an URL. * * @return resource name or `` (empty string) if the URL ends with a slash * (i.e. the resource is a collection). */ fun fileName(url: HttpUrl): String { val pathSegments = url.pathSegments() return pathSegments[pathSegments.size - 1] } fun listHeader(response: Response, name: String): Array<String> { val value = response.headers(name).joinToString(",") return value.split(',').filter { it.isNotEmpty() }.toTypedArray() Loading
src/test/java/at/bitfire/dav4android/DavResourceTest.kt +0 −9 Original line number Diff line number Diff line Loading @@ -47,15 +47,6 @@ class DavResourceTest { private fun sampleUrl() = mockServer.url("/dav/") @Test fun testFilename() { assertEquals("", DavResource(httpClient, sampleUrl().resolve("/")!!).fileName()) assertEquals("hier1", DavResource(httpClient, sampleUrl().resolve("/hier1")!!).fileName()) assertEquals("", DavResource(httpClient, sampleUrl().resolve("/hier1/")!!).fileName()) assertEquals("hier2", DavResource(httpClient, sampleUrl().resolve("/hier1/hier2")!!).fileName()) assertEquals("", DavResource(httpClient, sampleUrl().resolve("/hier1/hier2/")!!).fileName()) } @Test fun testOptions() { val url = sampleUrl() Loading
src/test/java/at/bitfire/dav4android/HttpUtilsTest.kt +11 −0 Original line number Diff line number Diff line Loading @@ -6,11 +6,22 @@ package at.bitfire.dav4android import okhttp3.HttpUrl import org.junit.Assert.assertEquals import org.junit.Test class HttpUtilsTest { @Test fun testFilename() { val sampleUrl = HttpUrl.parse("https://example.com")!! assertEquals("", HttpUtils.fileName(sampleUrl.resolve("/")!!)) assertEquals("hier1", HttpUtils.fileName(sampleUrl.resolve("/hier1")!!)) assertEquals("", HttpUtils.fileName(sampleUrl.resolve("/hier1/")!!)) assertEquals("hier2", HttpUtils.fileName(sampleUrl.resolve("/hier2")!!)) assertEquals("", HttpUtils.fileName(sampleUrl.resolve("/hier2/")!!)) } @Test fun testParseWwwAuthenticate() { // two schemes: one without param (illegal!), second with two params Loading