src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt

changeset 404
c7f4a5e81202
parent 392
c0c7b4ca2946
child 407
fa8274466c70
equal deleted inserted replaced
403:1c21d7a9135d 404:c7f4a5e81202
131 request.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, baseHref + value) 131 request.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, baseHref + value)
132 } 132 }
133 } 133 }
134 134
135 /** 135 /**
136 * The sanitized referer link, if any.
137 */
138 val referer: String? = this.sanitizeReferer(request.getAttribute(Constants.REQ_ATTR_REFERER) as String?)
139
140 /**
136 * The view object. 141 * The view object.
137 * 142 *
138 * @see Constants#REQ_ATTR_VIEWMODEL 143 * @see Constants#REQ_ATTR_VIEWMODEL
139 */ 144 */
140 var view: View? = null 145 var view: View? = null
230 fun i18n(key: String): String = ResourceBundle.getBundle("localization/strings", response.locale).getString(key) 235 fun i18n(key: String): String = ResourceBundle.getBundle("localization/strings", response.locale).getString(key)
231 236
232 fun sanitizeReferer(referer: String?): String? { 237 fun sanitizeReferer(referer: String?): String? {
233 if (referer == null) return null 238 if (referer == null) return null
234 // if someone really explicitly specifies the default port, we must support that, but we will remove it 239 // if someone really explicitly specifies the default port, we must support that, but we will remove it
235 val baseHrefWithPort = "${request.scheme}://${request.serverName}${request.serverPort}${request.contextPath}/" 240 val baseHrefWithPort = "${request.scheme}://${request.serverName}:${request.serverPort}${request.contextPath}/"
236 return if (referer.startsWith(baseHref)) { 241 return if (referer.startsWith(baseHref)) {
237 referer 242 referer
238 } else if (referer.startsWith(baseHrefWithPort)) { 243 } else if (referer.startsWith(baseHrefWithPort)) {
239 referer.replaceFirst(baseHrefWithPort, baseHref) 244 referer.replaceFirst(baseHrefWithPort, baseHref)
240 } else { 245 } else {

mercurial