Skip to content

Commit

Permalink
[split] TfeTapCompareFilter bug fixes, parameterize return type in fi…
Browse files Browse the repository at this point in the history
…nagle-http Message.with* * macaw-core/TfeTapCompareFilter.scala: Honor Content-Encoding (gunzip if gzipped) Parse content as stream, not string (choked on UTF-8) Use Guava to read bytes instead of dubious read loop Add stats

* finagle-http/Message.scala:
    with*: parameterize return type
  • Loading branch information
David Helder committed Jan 6, 2012
1 parent 71ceb40 commit ce6fd00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,3 +1,6 @@
??
* http: Message.withX methods now have parameterized return types

1.9.12 2012/01/05 1.9.12 2012/01/05


* SSLEngine: do not reuse between connections * SSLEngine: do not reuse between connections
Expand Down
17 changes: 10 additions & 7 deletions finagle-http/src/main/scala/com/twitter/finagle/http/Message.scala
Expand Up @@ -188,10 +188,11 @@ abstract class Message extends HttpMessage {
* Use content as InputStream. The underlying channel buffer's reader * Use content as InputStream. The underlying channel buffer's reader
* index is advanced. (Scala interface. Java users can use getInputStream().) * index is advanced. (Scala interface. Java users can use getInputStream().)
*/ */
def withInputStream(f: (InputStream => Unit)) { def withInputStream[T](f: InputStream => T): T = {
val inputStream = getInputStream() val inputStream = getInputStream()
f(inputStream) // throws val result = f(inputStream) // throws
inputStream.close() inputStream.close()
result
} }


/** /**
Expand All @@ -202,7 +203,7 @@ abstract class Message extends HttpMessage {
new ChannelBufferInputStream(getContent) new ChannelBufferInputStream(getContent)


/** Use content as Reader. (Scala interface. Java usrs can use getReader().) */ /** Use content as Reader. (Scala interface. Java usrs can use getReader().) */
def withReader(f: Reader => Unit) { def withReader[T](f: Reader => T): T = {
withInputStream { inputStream => withInputStream { inputStream =>
val reader = new InputStreamReader(inputStream) val reader = new InputStreamReader(inputStream)
f(reader) f(reader)
Expand Down Expand Up @@ -244,22 +245,24 @@ abstract class Message extends HttpMessage {
* (Java users can use this with a Function, or use Netty's ChannelBufferOutputStream * (Java users can use this with a Function, or use Netty's ChannelBufferOutputStream
* and then call setContent() with the underlying buffer.) * and then call setContent() with the underlying buffer.)
*/ */
def withOutputStream(f: (OutputStream => Unit)) { def withOutputStream[T](f: OutputStream => T): T = {
// Use buffer size of 1024. Netty default is 256, which seems too small. // Use buffer size of 1024. Netty default is 256, which seems too small.
// Netty doubles buffers on resize. // Netty doubles buffers on resize.
val outputStream = new ChannelBufferOutputStream(ChannelBuffers.dynamicBuffer(1024)) val outputStream = new ChannelBufferOutputStream(ChannelBuffers.dynamicBuffer(1024))
f(outputStream) // throws val result = f(outputStream) // throws
outputStream.close() outputStream.close()
write(outputStream.buffer) write(outputStream.buffer)
result
} }


/** Use as a Writer. Content is replaced with writer contents. */ /** Use as a Writer. Content is replaced with writer contents. */
def withWriter(f: (Writer => Unit)) { def withWriter[T](f: Writer => T): T = {
withOutputStream { outputStream => withOutputStream { outputStream =>
val writer = new OutputStreamWriter(outputStream) val writer = new OutputStreamWriter(outputStream)
f(writer) val result = f(writer)
writer.close() writer.close()
// withOutputStream will write() // withOutputStream will write()
result
} }
} }


Expand Down

0 comments on commit ce6fd00

Please sign in to comment.