Skip to content

Commit

Permalink
It Runs & Responds!
Browse files Browse the repository at this point in the history
The output buffer returned from MyResponse.outputBuffer's flush method is entertaining...needs to be much improved in order to work better.
  • Loading branch information
jrwest committed Feb 24, 2012
1 parent b755cda commit c4a9a4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/com/something/lift/NothingServer.scala
Expand Up @@ -66,7 +66,7 @@ object NothingServer extends App {
bootstrap.setOption("child.keepAlive", true)

val boundChannel = bootstrap.bind(new InetSocketAddress(8080))
println("TIME Server Started")
println("Lift-Netty Server Started")

allChannels.add(boundChannel)

Expand Down
12 changes: 11 additions & 1 deletion src/main/scala/com/something/lift/NothingServerHandler.scala
Expand Up @@ -10,6 +10,7 @@ import net.liftweb.http._
import java.util.Locale
import net.liftweb.util.{Helpers, Schedule, LoanWrapper}
import java.net.{InetSocketAddress, URI, URL}
import org.jboss.netty.buffer.ChannelBuffers

/**
* Created by IntelliJ IDEA.
Expand Down Expand Up @@ -338,7 +339,11 @@ class NettyHttpRequest extends HTTPRequest {

class MyResponse extends HTTPResponse {

lazy val nettyResponse: HttpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)
lazy val nettyResponse: HttpResponse = {
val r = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)
r.setContent(ChannelBuffers.dynamicBuffer(1024)) // TODO this is just some random choice, do something more intelligent?
r
}

/**
* Add cookies to the response
Expand Down Expand Up @@ -391,6 +396,11 @@ class NettyHttpRequest extends HTTPRequest {
def write(i: Int) {
nettyResponse.getContent.writeByte(i)
}

override def flush() {
val future = ctx.getChannel.write(nettyResponse)
future.addListener(ChannelFutureListener.CLOSE)
}
}
}

Expand Down

0 comments on commit c4a9a4c

Please sign in to comment.