Scoop API

scoop:scoop.http:0.1.0

src/message/authentication_info.scoop

Selected production source · src/message/authentication_info.scoop

1package scoop.http
3import scoop.bytes.ByteArrayBuilder
5/**
6 * Authentication response parameters, such as Digest response-authentication information.
7 */
8public class HttpAuthenticationInfo private constructor(
9 /**
10 * The parsed named parameters in their stored order.
11 */
12 public val parameters: Array<HttpParameter>) {
13 public constructor(parameters: List<HttpParameter>) : this(uniqueHttpParameters(parameters)) {}
15 /**
16 * Looks up a named parameter using ASCII case val folding, returning None when absent.
17 */
18 public fun parameter(name: String): HttpParameter? = findHttpParameter(parameters, name)
19 /**
20 * Serializes the structured value into HTTP field-value bytes.
21 */
22 public fun toByteArray(): Array<Byte> {
23 val output = ByteArrayBuilder()
24 appendHttpAuthParameters(output, parameters)
25 return output.toByteArray()
26 }
27 /**
28 * Builds an Authentication-Info response field.
29 */
30 public fun toAuthenticationInfoField(): HttpField = HttpField("Authentication-Info".toByteArray(), toByteArray())
31 /**
32 * Builds a Proxy-Authentication-Info response field.
33 */
34 public fun toProxyAuthenticationInfoField(): HttpField = HttpField("Proxy-Authentication-Info".toByteArray(), toByteArray())
36 /**
37 * Construction and parsing of this structured HTTP field.
38 */
39 public companion object {
40 /**
41 * Parses the complete field value, throwing HttpFieldParseException for malformed syntax.
42 */
43 public fun parse(value: List<Byte>, fieldName: String = "Authentication-Info"): HttpAuthenticationInfo {
44 val reader = HttpFieldReader(fieldName, value)
45 reader.skipOws()
46 return HttpAuthenticationInfo(readHttpAuthParameters(reader, false))
47 }
48 /**
49 * Parses the complete field value, throwing HttpFieldParseException for malformed syntax.
50 */
51 public fun parse(value: String, fieldName: String = "Authentication-Info"): HttpAuthenticationInfo =
52 parse(value.toByteArray(), fieldName)
53 /**
54 * Parses the complete value, returning None for HttpFieldParseException while propagating
55 * unrelated failures.
56 */
57 public fun parseOrNone(value: List<Byte>, fieldName: String = "Authentication-Info"): HttpAuthenticationInfo? {
58 try { return Some(parse(value, fieldName)) }
59 catch (_: HttpFieldParseException) { return None }
60 }
61 /**
62 * Parses the complete value, returning None for HttpFieldParseException while propagating
63 * unrelated failures.
64 */
65 public fun parseOrNone(value: String, fieldName: String = "Authentication-Info"): HttpAuthenticationInfo? =
66 parseOrNone(value.toByteArray(), fieldName)
67 /**
68 * Parses selected authentication-information fields, validating the combined parameters.
69 */
70 public fun parseFields(fields: List<HttpField>, fieldName: String = "Authentication-Info"): HttpAuthenticationInfo =
71 parse(combinedHttpAuthFields(fields, fieldName), fieldName)
72 }