/*
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.http11.*
import microservice.web.codecs.*
public class HttpServletResponse{
var res: Http11Res
public init(res: Http11Res){
this.res = res
}
public func addCookie(c: Cookie): Unit{
this.res.headers.put("Set-Cookie",c.toString())
}
public func containsHeader(header: String): Bool{
if (this.res.headers.get(header) == ""){
return true
} else{
return false
}
}
public func setHeader(key: String, value: String): Unit{
this.res.headers.put(key, value)
}
public func getHeader(key: String): String{
return this.res.headers.get(key)
}
public func setStatus(status: Int64): Unit{
this.res.code = status
}
public func getStatus(): Int64{
return this.res.code
}
public func sendRedirect(content: String): Unit{
}
public func setBody(body: String): Unit{
this.res.body = body
}
public func setBody(object: Object): Unit{
setHeader(HttpCommon.CONTENT_TYPE,MessageCodecs.getCodecs().getContentType())
this.res.body = MessageCodecs.getCodecs().toBody(object)
}
public func setBody(object: ResponseJsonObject): Unit{
setHeader(HttpCommon.CONTENT_TYPE,MessageCodecs.getCodecs().getContentType())
this.res.body = MessageCodecs.getCodecs().toBody(object)
}
}