Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make LiftRules.htmlProperties work #1342

Closed
wants to merge 2 commits into from

2 participants

@nafg

Previously only the first request in a session was taken into account.

@fmpwizard
Owner

+1 and thanks for adding a spec in the commit!

@fmpwizard
Owner

rebased to master

@fmpwizard fmpwizard closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 25, 2012
  1. @nafg
  2. @nafg

    Space changes

    nafg authored
This page is out of date. Refresh to see the latest.
View
17 web/webkit/src/main/scala/net/liftweb/http/LiftSession.scala
@@ -433,7 +433,7 @@ private[http] object RenderVersion {
}
/**
- * A trait defining how stateful the session is
+ * A trait defining how stateful the session is
*/
trait HowStateful {
private val howStateful = new ThreadGlobal[Boolean]
@@ -527,13 +527,10 @@ private[http] final case class AjaxRequestInfo(requestVersion: Long,
*/
class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
val httpSession: Box[HTTPSession]) extends LiftMerge with Loggable with HowStateful {
- val sessionHtmlProperties: SessionVar[HtmlProperties] =
- new SessionVar[HtmlProperties](LiftRules.htmlProperties.vend(
- S.request openOr Req.nil
- )) {}
+ def sessionHtmlProperties = LiftRules.htmlProperties.session.is.make openOr LiftRules.htmlProperties.default.is.vend
val requestHtmlProperties: TransientRequestVar[HtmlProperties] =
- new TransientRequestVar[HtmlProperties](sessionHtmlProperties.is) {}
+ new TransientRequestVar[HtmlProperties](sessionHtmlProperties(S.request openOr Req.nil)) {}
@volatile
private[http] var markedForTermination = false
@@ -635,7 +632,7 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
lastServiceTime = millis
LiftSession.onSetupSession.foreach(_(this))
- sessionHtmlProperties.is // cause the properties to be calculated
+ sessionHtmlProperties // cause the properties to be calculated
}
def running_? = _running_?
@@ -1670,7 +1667,7 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
val ret = findSnippetInstance(nameToTry)
// Update the snippetMap so that we reuse the same instance in this request (unless the snippet is transient)
ret.filter(TransientSnippet.notTransient(_)).foreach(s => snippetMap.set(snippetMap.is.updated(tagName, s)))
-
+
ret
}
}
@@ -1696,7 +1693,7 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
runWhitelist(snippet, cls, method, kids){(S.locateMappedSnippet(snippet).map(_(kids)) or
locSnippet(snippet)).openOr(
S.locateSnippet(snippet).map(_(kids)) openOr {
-
+
(locateAndCacheSnippet(cls)) match {
// deal with a stateless request when a snippet has
// different behavior in stateless mode
@@ -1838,7 +1835,7 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
e.snippetFailure,
e.buildStackTrace,
wholeTag)
-
+
case e: SnippetFailureException =>
reportSnippetError(page, snippetName,
e.snippetFailure,
View
66 web/webkit/src/test/scala/net/liftweb/http/HtmlPropertiesSpec.scala
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2011 WorldWide Conferencing, LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.liftweb
+package http
+
+import mockweb._
+
+
+import scala.xml.NodeSeq
+
+import common.{ Box, Empty, Full }
+
+/**
+* This only exists to keep the WebSpecSpec clean. Normally,
+* you could just use "() => bootstrap.Boot.boot".
+*/
+object HtmlPropertiesSpecBoot {
+ def boot() {
+ LiftRules.htmlProperties.default.set((_: Req) match {
+ case r @ Req("html5" :: _, _, _) =>
+ println("Html5 request: " + r)
+ Html5Properties(r.userAgent)
+ case r =>
+ println("other request: " + r)
+ OldHtmlProperties(r.userAgent)
+ })
+ }
+}
+
+class HtmlPropertiesSpec extends WebSpec(HtmlPropertiesSpecBoot.boot _) {
+ sequential
+
+ "LiftRules.htmlProperties.default function" should {
+ val testUrl1 = "http://example.com/html5/something"
+ val testUrl2 = "http://example.com/anotherurl"
+
+ val session1 = MockWeb.testS(testUrl1)(S.session)
+ val session2 = MockWeb.testS(testUrl2)(S.session)
+
+ "set S.htmlProperties to html5 when that is the first request" withSFor(testUrl1, session1) in {
+ S.htmlProperties must haveClass[Html5Properties]
+ }
+ "set S.htmlProperties to xhtml when that is not the first request" withSFor(testUrl2, session1) in {
+ S.htmlProperties must haveClass[OldHtmlProperties]
+ }
+ "set S.htmlProperties to xhtml when that is the first request" withSFor(testUrl2, session2) in {
+ S.htmlProperties must haveClass[OldHtmlProperties]
+ }
+ "set S.htmlProperties to html5 when that is not the first request" withSFor(testUrl1, session2) in {
+ S.htmlProperties must haveClass[Html5Properties]
+ }
+ }
+}
Something went wrong with that request. Please try again.