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

changeset 392
c0c7b4ca2946
parent 374
34abadbdd0e3
equal deleted inserted replaced
391:49f68aeb1dd2 392:c0c7b4ca2946
123 var redirectLocation: String? = null 123 var redirectLocation: String? = null
124 set(value) { 124 set(value) {
125 field = value 125 field = value
126 if (value == null) { 126 if (value == null) {
127 request.removeAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION) 127 request.removeAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION)
128 } else if (value.startsWith(baseHref)) {
129 request.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, value)
128 } else { 130 } else {
129 request.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, baseHref + value) 131 request.setAttribute(Constants.REQ_ATTR_REDIRECT_LOCATION, baseHref + value)
130 } 132 }
131 } 133 }
132 134
224 contentPage = Constants.JSP_COMMIT_SUCCESSFUL 226 contentPage = Constants.JSP_COMMIT_SUCCESSFUL
225 render() 227 render()
226 } 228 }
227 229
228 fun i18n(key: String): String = ResourceBundle.getBundle("localization/strings", response.locale).getString(key) 230 fun i18n(key: String): String = ResourceBundle.getBundle("localization/strings", response.locale).getString(key)
231
232 fun sanitizeReferer(referer: String?): String? {
233 if (referer == null) return null
234 // 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}/"
236 return if (referer.startsWith(baseHref)) {
237 referer
238 } else if (referer.startsWith(baseHrefWithPort)) {
239 referer.replaceFirst(baseHrefWithPort, baseHref)
240 } else {
241 null
242 }
243 }
229 } 244 }
230 245
231 /** 246 /**
232 * A path pattern optionally containing placeholders. 247 * A path pattern optionally containing placeholders.
233 * 248 *

mercurial