mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-06 21:18:31 +00:00
Have rest request also allow to get the content as a streamable
(note, this will break plugins that implement a rest handler..., like wares, thrift, and memcached, until they are upgraded)
This commit is contained in:
parent
1ffd68f2de
commit
016e2e7288
@ -20,9 +20,11 @@
|
||||
package org.elasticsearch.http.netty;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.http.HttpRequest;
|
||||
import org.elasticsearch.rest.support.AbstractRestRequest;
|
||||
import org.elasticsearch.rest.support.RestUtils;
|
||||
import org.elasticsearch.transport.netty.ChannelBufferStreamInputFactory;
|
||||
import org.jboss.netty.handler.codec.http.HttpMethod;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -101,6 +103,11 @@ public class NettyHttpRequest extends AbstractRestRequest implements HttpRequest
|
||||
return request.getContent().readableBytes() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInput contentStream() {
|
||||
return ChannelBufferStreamInputFactory.create(request.getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int contentLength() {
|
||||
return request.getContent().readableBytes();
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
@ -58,6 +59,11 @@ public interface RestRequest extends ToXContent.Params {
|
||||
*/
|
||||
boolean contentUnsafe();
|
||||
|
||||
/**
|
||||
* The content as a stream.
|
||||
*/
|
||||
StreamInput contentStream();
|
||||
|
||||
byte[] contentByteArray();
|
||||
|
||||
int contentByteArrayOffset();
|
||||
|
@ -0,0 +1,17 @@
|
||||
package org.elasticsearch.transport.netty;
|
||||
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ChannelBufferStreamInputFactory {
|
||||
|
||||
public static StreamInput create(ChannelBuffer buffer) {
|
||||
return new ChannelBufferStreamInput(buffer, buffer.readableBytes());
|
||||
}
|
||||
|
||||
public static StreamInput create(ChannelBuffer buffer, int size) {
|
||||
return new ChannelBufferStreamInput(buffer, size);
|
||||
}
|
||||
}
|
@ -212,7 +212,7 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
// netty always copies a buffer, either in NioWorker in its read handler, where it copies to a fresh
|
||||
// buffer, or in the cumlation buffer, which is cleaned each time
|
||||
StreamInput streamIn = new ChannelBufferStreamInput(buffer, size);
|
||||
StreamInput streamIn = ChannelBufferStreamInputFactory.create(buffer, size);
|
||||
|
||||
long requestId = buffer.readLong();
|
||||
byte status = buffer.readByte();
|
||||
|
Loading…
x
Reference in New Issue
Block a user