/*
Copyright (c) [2023] [squallzhao]
fountain is licensed under APACHE LICENSE, VERSION 2.0.
You can use this software according to the terms and conditions of the APACHE LICENSE, VERSION 2.0.
You may obtain a copy of APACHE LICENSE, VERSION 2.0 at: https://www.apache.org/licenses/LICENSE-2.0
*/
package microservice.web.server.reqres
import microservice.web.codecs.*
import microservice.web.http11.*
public class HttpServletRequest{
var req: Http11Req
var object : Option<Object> = Option<Object>.None
var cookies: Cookies = Cookies()
public init(req: Http11Req){
this.req = req
}
public func getBodyObject(): Object{
if (req.body.size>0){
if (let Some(v) <- object){
return v
} else{
this.object = MessageCodecs.getCodecs().fromBody(req.body)
}
}
return this.object.getOrThrow()
}
public func getCookie(key: String): Option<Cookie>{
getCookies()
return cookies.getMap().get(key)
}
public func getCookies(): Cookies{
if (cookies.getSize()>0){
return cookies
}
var data: String = req.headers.get("Cookie")
cookies.parse(data)
return cookies
}
public func getBody(): String{
return req.body
}
public func getAttribute(key: String): String{
return req.headers.get(key)
}
public func getParameter(key: String): String{
return req.params.get(key).getOrThrow()
}
public func getMethod(): String{
return req.getMethod()
}
public func getUri(): String{
return req.uri
}
public func getCharacterEncoding(): String{
return ""
}
public func getContentLength(): Int32{
return 0
}
public func getContentType(): String{
return req.headers.get(HttpCommon.CONTENT_TYPE)
}
public func getRemoteAddr(): String{
return ""
}
public func getRemoteHost(): String{
return ""
}
public func getContextPath(): String{
return req.uri
}
public func getQueryString(): String{
return req.queryString
}
}