diff options
author | Greg Wilkins | 2016-02-05 13:54:39 +0000 |
---|---|---|
committer | Greg Wilkins | 2016-02-05 13:54:39 +0000 |
commit | 7b5d12b3382d2dd50cdb690fd87af7df2f4aa7d2 (patch) | |
tree | e029317cb7359321370fb39c4a5a5d95b28748a9 /jetty-server/src/main/java | |
parent | 90efbe62c8b8580e6e864f59cdf9ea42c10c44fd (diff) | |
download | org.eclipse.jetty.project-7b5d12b3382d2dd50cdb690fd87af7df2f4aa7d2.tar.gz org.eclipse.jetty.project-7b5d12b3382d2dd50cdb690fd87af7df2f4aa7d2.tar.xz org.eclipse.jetty.project-7b5d12b3382d2dd50cdb690fd87af7df2f4aa7d2.zip |
Added HttpInput prepend content
Allows content to be reread
Diffstat (limited to 'jetty-server/src/main/java')
-rw-r--r-- | jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java index 1b6c4a8339..1f8c8b4857 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.nio.ByteBuffer; import java.util.ArrayDeque; +import java.util.Deque; import java.util.Objects; import java.util.Queue; import java.util.concurrent.TimeoutException; @@ -51,7 +52,7 @@ public class HttpInput extends ServletInputStream implements Runnable private final static Content EARLY_EOF_CONTENT = new EofContent("EARLY_EOF"); private final byte[] _oneByteBuffer = new byte[1]; - private final Queue<Content> _inputQ = new ArrayDeque<>(); + private final Deque<Content> _inputQ = new ArrayDeque<>(); private final HttpChannelState _channelState; private ReadListener _listener; private State _state = STREAM; @@ -370,6 +371,33 @@ public class HttpInput extends ServletInputStream implements Runnable } /** + * Adds some content to the start of this input stream. + * <p>Typically used to push back content that has + * been read, perhaps mutated. The bytes prepended are + * deducted for the contentConsumed total</p> + * @param item the content to add + * @return true if content channel woken for read + */ + public boolean prependContent(Content item) + { + boolean woken=false; + synchronized (_inputQ) + { + _inputQ.push(item); + _contentConsumed-=item.remaining(); + if (LOG.isDebugEnabled()) + LOG.debug("{} prependContent {}", this, item); + + if (_listener==null) + _inputQ.notify(); + else + woken=_channelState.onReadPossible(); + } + + return woken; + } + + /** * Adds some content to this input stream. * * @param item the content to add |