File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
main/kotlin/at/bitfire/dav4jvm
test/kotlin/at/bitfire/dav4jvm Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,30 @@ object HttpUtils {
49
49
return pathSegments.lastOrNull() ? : " "
50
50
}
51
51
52
+ /* *
53
+ * Gets all values of a header that is defined as a list [RFC 9110 5.6.1],
54
+ * regardless of they're sent as one line or as multiple lines.
55
+ *
56
+ * For instance, regardless of whether a server sends:
57
+ *
58
+ * ```
59
+ * DAV: 1
60
+ * DAV: 2
61
+ * ```
62
+ *
63
+ * or
64
+ *
65
+ * ```
66
+ * DAV: 1, 2
67
+ * ```
68
+ *
69
+ * this method would return `arrayOf("1","2")` for the `DAV` header.
70
+ *
71
+ * @param response the HTTP response to evaluate
72
+ * @param name header name (for instance: `DAV`)
73
+ *
74
+ * @return all values for the given header name
75
+ */
52
76
fun listHeader (response : Response , name : String ): Array <String > {
53
77
val value = response.headers(name).joinToString(" ," )
54
78
return value.split(' ,' ).filter { it.isNotEmpty() }.toTypedArray()
Original file line number Diff line number Diff line change @@ -1116,15 +1116,14 @@ class DavResourceTest {
1116
1116
.build())
1117
1117
}
1118
1118
1119
- @Test
1119
+ @Test(expected = DavException :: class )
1120
1120
fun testAssertMultiStatus_NonXML_ReallyNotXML () {
1121
1121
val dav = DavResource (httpClient, " https://from.com" .toHttpUrl())
1122
1122
dav.assertMultiStatus(okhttp3.Response .Builder ()
1123
1123
.request(Request .Builder ().url(dav.location).build())
1124
1124
.protocol(Protocol .HTTP_1_1 )
1125
1125
.code(207 ).message(" Multi-Status" )
1126
- .addHeader(" Content-Type" , " text/plain" )
1127
- .body(" Some error occurred" .toResponseBody())
1126
+ .body(" Some error occurred" .toResponseBody(" text/plain" .toMediaType()))
1128
1127
.build())
1129
1128
}
1130
1129
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ class QuotedStringUtilsTest {
22
22
assertEquals(" \"\\\\\" " , QuotedStringUtils .asQuotedString(" \\ " ))
23
23
}
24
24
25
+ @Test
25
26
fun testDecodeQuotedString () {
26
27
assertEquals(" \" " , QuotedStringUtils .decodeQuotedString(" \" " ))
27
28
assertEquals(" \\ " , QuotedStringUtils .decodeQuotedString(" \"\\\" " ))
You can’t perform that action at this time.
0 commit comments