Permalink
Browse files

deprecate HTTP codec in builder, move it to "http" instead.

  • Loading branch information...
1 parent 4cf1057 commit b0a212bcdddd049382a5350365d5873638cf5fc5 @mariusae mariusae committed Feb 25, 2011
@@ -5,6 +5,7 @@
import com.twitter.finagle.Codec;
+@Deprecated
public class Codec4J {
public static Codec<HttpRequest, HttpResponse> Http = new Http(0);
public static Codec<HttpRequest, HttpResponse> HttpWithCompression = new Http(6);
@@ -6,6 +6,7 @@ import org.jboss.netty.handler.codec.http._
import com.twitter.finagle.Codec
import com.twitter.finagle.http._
+@deprecated("Use com.twitter.finagle.http.Http instead")
class Http(compressionLevel: Int = 0) extends Codec[HttpRequest, HttpResponse] {
val clientPipelineFactory: ChannelPipelineFactory =
new ChannelPipelineFactory {
@@ -0,0 +1,71 @@
+package com.twitter.finagle.http
+
+/**
+ * This puts it all together: The HTTP codec itself.
+ */
+
+import org.jboss.netty.channel.{Channels, ChannelPipelineFactory}
+import org.jboss.netty.handler.codec.http._
+
+import com.twitter.util.StorageUnit
+import com.twitter.conversions.storage._
+
+import com.twitter.finagle.Codec
+
+case class Http(
+ _compressionLevel: Int = 0,
+ _maxChunkAggregationBufferSize: StorageUnit = 1.megabyte)
+ extends Codec[HttpRequest, HttpResponse] {
+
+ def compressionLevel(level: Int) = copy(_compressionLevel = level)
+ def maxChunkAggregationBufferSize(bufferSize: StorageUnit) =
+ copy(_maxChunkAggregationBufferSize = bufferSize)
+
+ val clientPipelineFactory: ChannelPipelineFactory =
+ new ChannelPipelineFactory {
+ def getPipeline() = {
+ val pipeline = Channels.pipeline()
+ pipeline.addLast("httpCodec", new HttpClientCodec())
+ pipeline.addLast(
+ "httpDechunker",
+ new HttpChunkAggregator(_maxChunkAggregationBufferSize.inBytes.toInt))
+
+ pipeline.addLast("httpDecompressor", new HttpContentDecompressor)
+
+ pipeline.addLast(
+ "connectionLifecycleManager",
+ new ClientConnectionManager)
+
+ pipeline
+ }
+ }
+
+ val serverPipelineFactory =
+ new ChannelPipelineFactory {
+ def getPipeline() = {
+ val pipeline = Channels.pipeline()
+ pipeline.addLast("httpCodec", new HttpServerCodec)
+ if (_compressionLevel > 0) {
+ pipeline.addLast(
+ "httpCompressor",
+ new HttpContentCompressor(_compressionLevel))
+ }
+
+ // Response to ``Expect: Continue'' requests.
+ pipeline.addLast("respondToExpectContinue", new RespondToExpectContinue)
+ pipeline.addLast(
+ "httpDechunker",
+ new HttpChunkAggregator(_maxChunkAggregationBufferSize.inBytes.toInt))
+
+ pipeline.addLast(
+ "connectionLifecycleManager",
+ new ServerConnectionManager)
+
+ pipeline
+ }
+ }
+}
+
+object Http {
+ def apply() = new Http()
+}
@@ -1,5 +1,11 @@
package com.twitter.finagle.http
+/**
+ * The HTTP connection manager implements connection management in
+ * accordance with RFC 2616 § 8. This is just the state machine: the
+ * codec implementations are in {Server,Client}ConnectionManager.
+ */
+
import org.jboss.netty.handler.codec.http._
class ConnectionManager {

0 comments on commit b0a212b

Please sign in to comment.