<commit_before>package eu.delving.lib

import net.liftweb.common._
import eu.delving.model._
import net.liftweb.http.rest.{JsonXmlAble, RestHelper}

/**
 * Dispatch the services
 *
 * @author <NAME> <<EMAIL>>
 */


object BrowseService extends RestHelper {

  val log = Logger("BrowseService")

  override protected def defaultGetAsJson: Boolean = false

  case class Response(response: AnyRef) extends JsonXmlAble

  serveJx[Response] {
    case "service" :: "user" :: Nil Get _ if User.notLoggedIn_? => Full(Response(User.findAll.head.getPublic))
    case "service" :: "user" :: Nil Get _ if User.loggedIn_? => Full(Response(User.findAll.head.getPrivate))
  }

}<commit_msg>Avoiding handling if the client accepts HTML (ie. is a browser), unless they use format=xml|json param<commit_after>package eu.delving.lib

import eu.delving.model._
import net.liftweb.http.rest.{JsonXmlAble, RestHelper}
import net.liftweb.common._
import net.liftweb.http.Req

/**
 * Dispatch the services
 *
 * @author <NAME> <<EMAIL>>
 */


object BrowseService extends RestHelper {

  val log = Logger("BrowseService")

  def acceptsHtml(in: Req) = in.weightedAccept.find(_.matches("text" -> "html")).isDefined

  override protected def jsonResponse_?(in: Req): Boolean = (in.acceptsJson_? && !acceptsHtml(in)) || in.param("format") == "json"
  override protected def xmlResponse_?(in: Req): Boolean = (in.acceptsXml_? && !acceptsHtml(in)) || in.param("format") == "xml"

  case class Response(response: AnyRef) extends JsonXmlAble

  def give(any : AnyRef) = Full(Response(any))

  serveJx[Response] {
    case "service" :: "user" :: Nil Get _ if User.notLoggedIn_? => give(User.findAll.head.getPublic)
    case "service" :: "user" :: Nil Get _ if User.loggedIn_? => give(User.findAll.head.getPrivate)
  }

}
{'fraction_non_alphanumeric': 0.14253773057574065, 'fraction_numerical': 0.0, 'mean_word_length': 4.646687697160884, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5994293', 'n_tokens_mistral': 613, 'n_tokens_neox': 591, 'n_words': 142}