github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

dpp / liftweb

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 420
    • 41
  • Source
  • Commits
  • Network (41)
  • Downloads (22)
  • Wiki (32)
  • Graphs
  • Tree: d983b21

click here to add a description

click here to add a homepage

  • Branches (58)
    • 1.0_maint
    • 280_port
    • 280_port_refresh
    • Lift-1.1-M8
    • Lift-2.0-M1
    • backport_issue_313
    • dirk_wip_issues_131_132
    • dpp_issue_308
    • dpp_issue_314
    • dpp_issue_319
    • dpp_issue_335
    • dpp_issue_a_2
    • dpp_issues_254_315_290_284
    • dpp_wip_1_0_3
    • dpp_wip_dogscape
    • hseeberger_issue_326
    • irc_changes_fix
    • irc_issue_161
    • irc_issue_167
    • irc_issue_168
    • irc_issue_228_252
    • irc_issue_253
    • irc_issue_288
    • irc_issue_292
    • irc_issue_307_330_332
    • irc_wip_archetype_enhance
    • irc_wip_lift20
    • irc_wip_restruct
    • irc_wip_restruct_stage
    • jnm_issue_155
    • jnm_issue_309
    • jon_issue_297
    • jon_issue_336
    • joni_improved_extraction
    • joni_issue_279
    • joni_issue_323
    • joni_json_streaming_parser
    • joni_serialization_optimization
    • kjn-bindings-wip
    • kjn-jpa-fix
    • marius_opt
    • master
    • mstarzyk_wip_sbt
    • new_actor
    • pr1001_issue_322
    • rmm_wip_couch
    • wip-boolean-can
    • wip-dcb-derby-binary
    • wip-dcb-issue-89-jodatime
    • wip-dcb-jpa-validation
    • wip-dcb-postgresql-autokey-1.1
    • wip-jta-jonas
    • wip-nafg-date
    • wip-nafg-mapperfk
    • wip-nafg-tableeditor
    • wip-ol-immu
    • wip-prettify
    • wip_tim_285
  • Tags (22)
    • teched08_demo_jam
    • osgi01
    • lift-site-skin-2.0-M1
    • lift-parent-2.0-M1
    • innovation_games_oneline_1_0
    • igo_1_0
    • buy_a_feature_svn_130
    • bonded_to_rev_121_baf_dpp
    • Lift-2.0-M1-release
    • Lift-1.1-M8-release
    • 1.1-M7
    • 1.1-M6
    • 1.1-M5
    • 1.1-M4
    • 1.1-M3
    • 1.1-M1
    • 1.0.3
    • 1.0.2
    • 1.0.1
    • 1.0
    • 0.10
    • 0.9
Sending Request…
Click here to lend your support to: liftweb and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

The Lift web framework for Scala — Read more

  cancel

http://liftweb.net

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added the JQ CSS helper 
dpp (author)
Thu Mar 19 07:27:17 -0700 2009
commit  d983b2136ccc578631e4927abf3db5a63bb09d2d
tree    518b2fa47ba70263d8b8791c35a8dc10716041c7
parent  52d4f7aca7dc152a50e7f141954a5c18996d0965
liftweb / lift / src / main / scala / net / liftweb / http / HttpResponse.scala lift/src/main/scala/net/liftweb/http/HttpResponse.scala
100644 452 lines (379 sloc) 14.646 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/*
* Copyright 2007-2008 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.http
 
import _root_.scala.xml.{Node, Unparsed, Group, NodeSeq}
import _root_.net.liftweb.util._
import _root_.javax.servlet.http.Cookie
import js._
import _root_.net.liftweb.util.Helpers._
 
/**
* 200 response but without body.
*/
case class OkResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 200)
}
 
trait HeaderStuff {
   val headers = S.getHeaders(Nil)
   val cookies = S.responseCookies
}
 
/**
* 201 Created Response
*
* The Resource was created. We then return the resource, post-processing, to
* the client. Usually used with HTTP PUT.
*/
case class CreatedResponse(xml: Node, mime: String) extends NodeResponse {
  def docType = Empty
  def code = 201
  def headers = List("Content-Type" -> mime)
  def cookies = Nil
  def out = xml
}
 
/**
* 202 response but without body.
*/
case class AcceptedResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 202)
}
 
/**
* 204 response but without body.
*/
case class NoContentResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 204)
}
 
/**
* 205 response but without body.
*/
case class ResetContentResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 205)
}
 
/**
* 301 Redirect.
*/
case class PermRedirectResponse(uri: String, request: Req, cookies: Cookie*) extends LiftResponse {
  def toResponse = InMemoryResponse(Array(), List("Location" -> request.updateWithContextPath(uri)), cookies.toList, 301)
}
 
/**
* 307 Redirect.
*/
case class TemporaryRedirectResponse(uri: String, request: Req, cookies: Cookie*) extends LiftResponse {
  def toResponse = InMemoryResponse(Array(), List("Location" -> request.updateWithContextPath(uri)), cookies.toList, 307)
}
 
/**
* 400 Bad Request
*
* Your Request was missing an important element. Use this as a last resort if
* the request appears incorrect.
*/
case class BadResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 400)
}
 
/**
* 401 Unauthorized Response.
*/
case class UnauthorizedResponse(realm: String) extends LiftResponse {
  def toResponse = InMemoryResponse(Array(), List("WWW-Authenticate" -> ("Basic realm=\"" + realm + "\"")), Nil, 401)
}
 
object Qop extends Enumeration(0, "auth", "auth-int", "auth,auth-int") {
  val AUTH, AUTH_INT, AUTH_AND_AUTH_INT = Value
}
 
/**
* 401 Unauthorized Response.
*/
case class UnauthorizedDigestResponse(override val realm: String, qop: Qop.Value, nonce: String, opaque: String) extends UnauthorizedResponse(realm) {
  override def toResponse = InMemoryResponse(Array(), List("WWW-Authenticate" -> (
        "Digest realm=\"" + realm + "\", " +
        "qop=\"" + qop + "\", " +
        "nonce=\"" + nonce + "\", " +
        "opaque=\"" + opaque + "\""
      )), Nil, 401)
}
 
/**
* 403 Forbidden
*
* The server understood the request, but is refusing to fulfill it.
* Authorization will not help and the request SHOULD NOT be repeated.
*/
case class ForbiddenResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 403)
}
 
/**
* 404 Not Found
*
* The server has not found anything matching the Request-URI.
*/
case class NotFoundResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 404)
}
 
/**
* 405 Method Not Allowed
*
* This Resource does not allow this method. Use this when the resource can't
* understand the method no matter the circumstances.
*/
case class MethodNotAllowedResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 405)
}
 
/**
* 406 Not Acceptable
*
* This Resource does not allow this method. Use this when the resource can't
* understand the method no matter the circumstances.
*/
case class NotAcceptableResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 406)
}
 
/**
* 410 Resource Gone
*
* The requested Resource used to exist but no longer does.
*/
case class GoneResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 410)
}
 
/**
* 415 Resource Gone
*
* The requested Resource used to exist but no longer does.
*/
case class UnsupportedMediaTypeResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 415)
}
 
/**
* 500 Internal Server Error
*
* The server encountered an unexpected condition which prevented
* it from fulfilling the request.
*/
case class InternalServerErrorResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 500)
}
 
/**
* 501 Not Implemented
*
* The server does not support the functionality required to
* fulfill the request. This is the appropriate response when the
* server does not recognize the request method and is not capable
* of supporting it for any resource.
*/
case class NotImplementedResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 501)
}
 
/**
* 502 Bad Gateway
*
* The server, while acting as a gateway or proxy, received an invalid
* response from the upstream server it accessed in attempting
* to fulfill the request.
*/
case class BadGatewayResponse() extends LiftResponse with HeaderStuff {
  def toResponse = InMemoryResponse(Array(), headers, cookies, 502)
}
 
/**
* 503 Bad Gateway
*
* The server, while acting as a gateway or proxy, received an invalid
* response from the upstream server it accessed in attempting
* to fulfill the request.
*/
case class ServiceUnavailableResponse(retryAfter: Long) extends LiftResponse {
  def toResponse = InMemoryResponse(Array(), List("Retry-After" -> retryAfter.toString), Nil, 503)
}
 
object JavaScriptResponse {
  def apply(js: JsCmd): LiftResponse = JavaScriptResponse(js, S.getHeaders(Nil), S.responseCookies, 200)
}
 
/**
* Impersonates a HTTP response having Content-Type = text/javascript
*/
case class JavaScriptResponse(js: JsCmd, headers: List[(String, String)], cookies: List[Cookie], code: Int) extends LiftResponse {
  def toResponse = {
    val bytes = js.toJsCmd.getBytes("UTF-8")
    InMemoryResponse(bytes, ("Content-Length", bytes.length.toString) :: ("Content-Type", "text/javascript") :: headers, cookies, code)
  }
}
 
trait LiftResponse {
  def toResponse: BasicResponse
}
 
object JsonResponse extends HeaderStuff {
  def apply(json: JsExp): LiftResponse = JsonResponse(json, headers, cookies, 200)
}
 
case class JsonResponse(json: JsExp, headers: List[(String, String)], cookies: List[Cookie], code: Int) extends LiftResponse {
def toResponse = {
val bytes = json.toJsCmd.getBytes("UTF-8")
InMemoryResponse(bytes, ("Content-Length", bytes.length.toString) :: ("Content-Type", "application/json") :: headers, cookies, code)
}
}
 
sealed trait BasicResponse extends LiftResponse {
  def headers: List[(String, String)]
  def cookies: List[Cookie]
  def code: Int
  def size: Long
}
 
final case class InMemoryResponse(data: Array[Byte], headers: List[(String, String)], cookies: List[Cookie], code: Int) extends BasicResponse {
  def toResponse = this
  def size = data.length
 
  override def toString="InMemoryResponse("+(new String(data, "UTF-8"))+", "+headers+", "+cookies+", "+code+")"
}
 
final case class StreamingResponse(data: {def read(buf: Array[Byte]): Int}, onEnd: () => Unit, size: Long, headers: List[(String, String)], cookies: List[Cookie], code: Int) extends BasicResponse {
  def toResponse = this
 
    override def toString="StreamingResponse( steaming_data , "+headers+", "+cookies+", "+code+")"
}
 
case class RedirectResponse(uri: String, cookies: Cookie*) extends LiftResponse {
  // The Location URI is not resolved here, instead it is resolved with context path prior of sending the actual response
  def toResponse = InMemoryResponse(Array(0), List("Location" -> uri), cookies toList, 302)
}
 
object DoRedirectResponse {
  def apply(url: String): LiftResponse = RedirectResponse(url, Nil :_*)
}
 
case class RedirectWithState(override val uri: String, state : RedirectState, override val cookies: Cookie*) extends RedirectResponse(uri, cookies:_*)
 
object RedirectState {
  def apply(f: () => Unit, msgs: (String, NoticeType.Value)*): RedirectState = new RedirectState(Full(f), msgs :_*)
}
case class RedirectState(func: Box[() => Unit], msgs : (String, NoticeType.Value)*)
 
object MessageState {
  implicit def tuple2MessageState(msg : (String, NoticeType.Value)) = MessageState(msg)
}
 
case class MessageState(override val msgs: (String, NoticeType.Value)*) extends RedirectState(Empty, msgs :_*)
 
/**
* Stock XHTML doctypes available to the lift programmer.
*/
object DocType {
  val xhtmlTransitional = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
 
  val xhtmlStrict = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
 
  val xhtmlFrameset = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"
 
  val xhtml11 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"
 
  val xhtmlMobile = "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">"
}
 
object ResponseInfo {
  var docType: PartialFunction[Req, Box[String]] = {
    case _ if S.getDocType._1 => S.getDocType._2
    case _ => Full(DocType.xhtmlTransitional)
  }
}
 
 
object PlainTextResponse {
  def apply(text: String): PlainTextResponse = PlainTextResponse(text, Nil, 200)
  def apply(text: String, code: Int): PlainTextResponse = PlainTextResponse(text, Nil, code)
}
 
case class PlainTextResponse(text: String, headers: List[(String, String)], code: Int) extends LiftResponse {
  def toResponse = {
    val bytes = text.getBytes("UTF-8")
    InMemoryResponse(bytes, ("Content-Length", bytes.length.toString) :: ("Content-Type", "text/plain") :: headers, Nil, code)
  }
}
 
object CSSResponse {
  def apply(text: String): CSSResponse = CSSResponse(text, Nil, 200)
  def apply(text: String, code: Int): CSSResponse = CSSResponse(text, Nil, code)
}
 
case class CSSResponse(text: String, headers: List[(String, String)], code: Int) extends LiftResponse {
  def toResponse = {
    val bytes = text.getBytes("UTF-8")
    InMemoryResponse(bytes, ("Content-Length", bytes.length.toString) :: ("Content-Type", "text/css") :: headers, Nil, code)
  }
}
 
trait NodeResponse extends LiftResponse {
  def out: Node
  def headers: List[(String, String)]
  def cookies: List[Cookie]
  def code: Int
  def docType: Box[String]
  def renderInIEMode: Boolean = false
 
  def toResponse = {
    val encoding: String =
    (out, headers.ciGet("Content-Type")) match {
      case (up: Unparsed, _) => ""
 
      case (_, Empty) | (_, Failure(_, _, _)) =>
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 
      case (_, Full(s)) if (s.toLowerCase.startsWith("text/html")) =>
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 
      case (_, Full(s)) if (s.toLowerCase.startsWith("text/xml") ||
                            s.toLowerCase.startsWith("text/xhtml") ||
                            s.toLowerCase.startsWith("application/xml") ||
                            s.toLowerCase.startsWith("application/xhtml+xml")) =>
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 
      case _ => ""
    }
 
    val doc = docType.map(_ + "\n") openOr ""
 
    val sb = new StringBuilder(64000)
 
    sb.append(encoding)
    sb.append(doc)
    AltXML.toXML(out, _root_.scala.xml.TopScope,
                 sb, false, false, renderInIEMode)
 
    sb.append(" \n ")
 
    val ret = sb.toString
 
    InMemoryResponse(ret.getBytes("UTF-8"), headers, cookies, code)
  }
}
 
case class XhtmlResponse(out: Node, docType: Box[String],
                         headers: List[(String, String)],
                         cookies: List[Cookie],
                         code: Int,
                         override val renderInIEMode: Boolean) extends NodeResponse
 
 
/**
* Allows you to create custom 200 responses for clients using different
* Content-Types.
*/
case class XmlMimeResponse(xml: Node, mime: String) extends NodeResponse {
  def docType = Empty
  def code = 200
  def headers = List("Content-Type" -> mime)
  def cookies = Nil
  def out = xml
}
 
case class XmlResponse(xml: Node) extends NodeResponse {
  def docType = Empty
  def code = 200
  def headers = List("Content-Type" -> "text/xml")
  def cookies = Nil
  def out = xml
}
 
/**
* Returning an Atom document.
*/
case class AtomResponse(xml: Node) extends NodeResponse {
  def docType = Empty
  def code = 200
  def headers = List("Content-Type" -> "application/atom+xml")
  def cookies = Nil
  def out = xml
}
 
/**
* Returning an OpenSearch Description Document.
*/
case class OpenSearchResponse(xml: Node) extends NodeResponse {
  def docType = Empty
  def code = 200
  def headers = List("Content-Type" -> "application/opensearchdescription+xml")
  def cookies = Nil
  def out = xml
}
 
/**
* The Atom entity was successfully created and is shown to the client.
*/
case class AtomCreatedResponse(xml: Node) extends LiftResponse {
  def toResponse = CreatedResponse(xml, "application/atom+xml").toResponse
}
 
/**
* Returning an Atom category document.
*/
case class AtomCategoryResponse(xml: Node) extends LiftResponse {
  def toResponse = XmlMimeResponse(xml, "application/atomcat+xml").toResponse
}
 
/**
* Returning an Atom Service Document.
*/
case class AtomServiceResponse(xml: Node) extends LiftResponse {
  def toResponse = XmlMimeResponse(xml, "application/atomsvc+xml").toResponse
}
 
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server