1 package net.pterodactylus.sone.utils
3 import freenet.support.api.HTTPRequest
4 import net.pterodactylus.sone.web.page.FreenetRequest
5 import net.pterodactylus.util.web.Method.GET
6 import net.pterodactylus.util.web.Method.POST
7 import net.pterodactylus.util.web.Request
9 val Request.isGET get() = this.method == GET
10 val Request.isPOST get() = this.method == POST
11 val HTTPRequest.isGET get() = method == "GET"
12 val HTTPRequest.isPOST get() = method == "POST"
14 val FreenetRequest.parameters get() = Parameters(httpRequest)
15 val HTTPRequest.parameters get() = Parameters(this)
17 class Parameters(private val request: HTTPRequest) {
18 operator fun get(name: String, maxLength: Int = 1048576) = when {
19 request.isGET -> request.getParam(name)
20 request.isPOST -> request.getPartAsStringFailsafe(name, maxLength)
24 operator fun contains(name: String) = when {
25 request.isGET -> request.isParameterSet(name)
26 request.isPOST -> request.isPartSet(name)
31 val FreenetRequest.headers get() = Headers(httpRequest)
32 val HTTPRequest.headers get() = Headers(this)
34 class Headers(private val request: HTTPRequest) {
35 operator fun get(name: String): String? = request.getHeader(name.toLowerCase())