Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5709fd38 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Webcal subscriptions: handle webcal(s):// URLs and treat them as http(s)://

parent 4bf9ba5f
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -105,4 +105,31 @@ class CollectionTest {
        assertTrue(info.supportsVJOURNAL!!)
    }

    @Test
    @SmallTest
    fun testFromDavResponseWebcal() {
        // Webcal subscription
        server.enqueue(MockResponse()
                .setResponseCode(207)
                .setBody("<multistatus xmlns='DAV:' xmlns:CS='http://calendarserver.org/ns/'>" +
                        "<response>" +
                        "   <href>/webcal1</href>" +
                        "   <propstat><prop>" +
                        "       <displayname>Sample Subscription</displayname>" +
                        "       <resourcetype><collection/><CS:subscribed/></resourcetype>" +
                        "       <CS:source><href>webcals://example.com/1.ics</href></CS:source>" +
                        "   </prop></propstat>" +
                        "</response>" +
                        "</multistatus>"))

        lateinit var info: Collection
        DavResource(httpClient.okHttpClient, server.url("/"))
                .propfind(0, ResourceType.NAME) { response, _ ->
                    info = Collection.fromDavResponse(response) ?: throw IllegalArgumentException()
                }
        assertEquals(Collection.TYPE_WEBCAL, info.type)
        assertEquals("Sample Subscription", info.displayName)
        assertEquals(HttpUrl.get("https://example.com/1.ics"), info.source)
    }

}
+6 −1
Original line number Diff line number Diff line
@@ -115,7 +115,12 @@ data class Collection(
                            supportsVJOURNAL = it.supportsJournal
                        }
                    } else { // Type.WEBCAL
                        dav[Source::class.java]?.let { source = it.hrefs.firstOrNull()?.let { HttpUrl.parse(it) } }
                        dav[Source::class.java]?.let { source = it.hrefs.firstOrNull()?.let { rawHref ->
                            val href = rawHref
                                    .replace("^webcal://".toRegex(), "http://")
                                    .replace("^webcals://".toRegex(), "https://")
                            HttpUrl.parse(href)
                        } }
                        supportsVEVENT = true
                    }
                }