feat: StructuredFieldを扱えるように
This commit is contained in:
parent
e438411685
commit
c15cb74b73
|
@ -1,5 +1,6 @@
|
|||
package dev.usbharu.httpsignature.v2
|
||||
|
||||
import org.greenbytes.http.sfv.Parser
|
||||
import java.net.http.HttpRequest
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
|
@ -56,15 +57,30 @@ class SignatureBaseBuilder {
|
|||
return this
|
||||
}
|
||||
|
||||
fun header(headerName:String,headerValues:List<String>): SignatureBaseBuilder {
|
||||
fun header(headerName: String, headerValues: List<String>): SignatureBaseBuilder {
|
||||
signatureBase.addComponent(HttpMessageComponent(headerName, headerValues))
|
||||
return this
|
||||
}
|
||||
|
||||
fun header(headerName: String,headerValue:String): SignatureBaseBuilder {
|
||||
fun header(headerName: String, headerValue: String): SignatureBaseBuilder {
|
||||
return header(headerName, listOf(headerValue))
|
||||
}
|
||||
|
||||
fun structuredFieldItem(fieldName: String, fieldValue: String): SignatureBaseBuilder {
|
||||
signatureBase.addComponent(StructuredFieldComponent(fieldName, Parser(fieldValue).parseItem()))
|
||||
return this
|
||||
}
|
||||
|
||||
fun structuredFieldList(fieldName: String, fieldValue: String): SignatureBaseBuilder {
|
||||
signatureBase.addComponent(StructuredFieldComponent(fieldName, Parser(fieldValue).parseList()))
|
||||
return this
|
||||
}
|
||||
|
||||
fun structuredFieldDictionary(fieldName: String, fieldValue: String): SignatureBaseBuilder {
|
||||
signatureBase.addComponent(StructuredFieldComponent(fieldName, Parser(fieldValue).parseDictionary()))
|
||||
return this
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromHttpRequest(httpRequest: HttpRequest): SignatureBaseBuilder {
|
||||
val signatureBaseBuilder = SignatureBaseBuilder()
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package dev.usbharu.httpsignature.v2
|
||||
|
||||
import org.greenbytes.http.sfv.Type
|
||||
|
||||
class StructuredFieldComponent(val name: String, val structuredField: Type<*>) : Component {
|
||||
override val componentName: String
|
||||
get() = name
|
||||
override val componentParameter: String
|
||||
get() = "sf"
|
||||
override val componentValue: String
|
||||
get() = structuredField.serialize()
|
||||
}
|
Loading…
Reference in New Issue