Netty 4 based transport implementation plugin for Elasticsearch providing high-performance networking layer for HTTP and node-to-node communications
—
The HTTP Server Transport provides the REST API interface for Elasticsearch, handling HTTP requests from clients and applications. Built on Netty 4, it supports HTTP/1.1 with features like request pipelining, compression, and efficient resource management.
Core HTTP server implementation extending Elasticsearch's AbstractHttpServerTransport with Netty4-specific HTTP handling.
/**
* Netty4 implementation of HTTP server transport for REST API access
* Handles HTTP requests, response processing, and client connections
*/
public class Netty4HttpServerTransport extends AbstractHttpServerTransport {
// HTTP-specific configuration settings
public static Setting<Integer> SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS;
public static final Setting<Integer> SETTING_HTTP_WORKER_COUNT;
public static final Setting<ByteSizeValue> SETTING_HTTP_NETTY_RECEIVE_PREDICTOR_SIZE;
}Performance and resource configuration settings for optimal HTTP request handling.
/**
* Maximum number of components in composite buffers for HTTP responses
* Higher values allow more efficient memory usage for large responses
*/
public static Setting<Integer> SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = new Setting<>(
"http.netty.max_composite_buffer_components",
(s) -> {
// Calculate based on max content length
ByteSizeValue maxContentLength = SETTING_HTTP_MAX_CONTENT_LENGTH.get(s);
return Integer.toString(Math.max((int) (maxContentLength.getBytes() / 1024), 64));
},
(s) -> Setting.parseInt(s, 2, "http.netty.max_composite_buffer_components"),
Property.NodeScope
);
/**
* Number of worker threads for HTTP request processing
* 0 means shared with transport layer, >0 creates dedicated HTTP workers
*/
public static final Setting<Integer> SETTING_HTTP_WORKER_COUNT = Setting.intSetting(
"http.netty.worker_count",
0,
Property.NodeScope
);
/**
* Initial buffer size for HTTP receive buffer prediction
* Netty adaptively adjusts based on actual request sizes
*/
public static final Setting<ByteSizeValue> SETTING_HTTP_NETTY_RECEIVE_PREDICTOR_SIZE = Setting.byteSizeSetting(
"http.netty.receive_predictor_size",
new ByteSizeValue(64, ByteSizeUnit.KB),
Property.NodeScope
);Configuration Example:
Settings httpSettings = Settings.builder()
.put("http.netty.worker_count", 0) // Share with transport
.put("http.netty.max_composite_buffer_components", 128)
.put("http.netty.receive_predictor_size", "64kb")
.build();HTTP request representation wrapping Netty HTTP requests with Elasticsearch-specific functionality.
/**
* Netty4 implementation of HTTP request interface
* Wraps Netty HttpRequest with Elasticsearch-specific methods
*/
public class Netty4HttpRequest implements HttpRequest {
/**
* Gets HTTP method for this request
* @return REST request method (GET, POST, PUT, DELETE, etc.)
*/
RestRequest.Method method();
/**
* Gets request URI including path and query parameters
* @return Full request URI string
*/
String uri();
/**
* Gets request body content as bytes
* @return BytesReference containing request body
*/
BytesReference content();
/**
* Releases request resources immediately
* Must be called when request processing is complete
*/
void release();
/**
* Creates a copy of request and releases original
* Useful for async processing where original request lifecycle differs
* @return New HttpRequest copy with independent lifecycle
*/
HttpRequest releaseAndCopy();
/**
* Gets all HTTP headers as map
* @return Map of header names to list of values
*/
Map<String, List<String>> getHeaders();
/**
* Gets cookies from request headers
* @return List of cookie strings
*/
List<String> strictCookies();
/**
* Gets HTTP protocol version
* @return HttpVersion (HTTP/1.0, HTTP/1.1, etc.)
*/
HttpVersion protocolVersion();
/**
* Removes specific header from request
* @param header Header name to remove
* @return Modified HttpRequest instance
*/
HttpRequest removeHeader(String header);
/**
* Creates HTTP response for this request
* @param status HTTP status code
* @param contentRef Response body content
* @return Netty4HttpResponse ready to send
*/
Netty4HttpResponse createResponse(RestStatus status, BytesReference contentRef);
/**
* Gets exception from inbound request processing if any
* @return Exception or null if no error
*/
Exception getInboundException();
/**
* Gets underlying Netty HTTP request object
* @return Native Netty HttpRequest for low-level access
*/
io.netty.handler.codec.http.HttpRequest getNettyRequest();
}Usage Example:
// Request received by HTTP transport
Netty4HttpRequest request = // from transport pipeline
// Process request details
RestRequest.Method method = request.method(); // GET, POST, etc.
String uri = request.uri(); // "/index/_search?q=query"
BytesReference body = request.content(); // Request payload
// Access headers
Map<String, List<String>> headers = request.getHeaders();
String contentType = headers.get("Content-Type").get(0);
// Create response
Netty4HttpResponse response = request.createResponse(
RestStatus.OK,
new BytesArray("{\"result\":\"success\"}")
);
// Always release request resources
request.release();Static utility methods for converting between Netty and Elasticsearch HTTP method representations.
/**
* Translates Netty HTTP method to Elasticsearch REST method
* @param httpMethod Netty HttpMethod instance
* @return Corresponding RestRequest.Method
*/
public static RestRequest.Method translateRequestMethod(HttpMethod httpMethod);
/**
* Converts Netty HTTP headers to standard Java map format
* @param httpHeaders Netty HttpHeaders instance
* @return Map with header names and values
*/
public static Map<String, List<String>> getHttpHeadersAsMap(HttpHeaders httpHeaders);HTTP response implementation providing efficient response generation and transmission.
/**
* Netty4 implementation of HTTP response
* Extends Netty's DefaultFullHttpResponse with Elasticsearch functionality
*/
public class Netty4HttpResponse extends DefaultFullHttpResponse implements HttpResponse {
// Response creation and content management
// Headers manipulation and status setting
// Resource lifecycle management
}HTTP channel implementations for managing client connections and server binding.
/**
* HTTP channel for client connections
* Handles request/response exchange with individual HTTP clients
*/
public class Netty4HttpChannel implements HttpChannel {
/**
* Sends HTTP response to client asynchronously
* @param response HTTP response to send
* @param listener Callback for send completion
*/
void sendResponse(HttpResponse response, ActionListener<Void> listener);
/**
* Gets local address for this HTTP connection
* @return Local InetSocketAddress
*/
InetSocketAddress getLocalAddress();
/**
* Gets remote client address for this connection
* @return Remote InetSocketAddress of HTTP client
*/
InetSocketAddress getRemoteAddress();
/**
* Closes HTTP connection to client
*/
void close();
}
/**
* HTTP server channel for accepting client connections
* Binds to configured port and accepts HTTP connections
*/
public class Netty4HttpServerChannel implements HttpServerChannel {
/**
* Gets local socket address server is bound to
* @return Local InetSocketAddress for HTTP server
*/
InetSocketAddress getLocalAddress();
/**
* Adds listener for server channel close events
* @param listener Callback for close notification
*/
void addCloseListener(ActionListener<Void> listener);
/**
* Checks if HTTP server is currently accepting connections
* @return true if server is open, false otherwise
*/
boolean isOpen();
/**
* Closes HTTP server and stops accepting connections
*/
void close();
}Request processing pipeline handlers for HTTP protocol processing.
/**
* HTTP request pipelining handler supporting concurrent request processing
* Ensures responses are sent in same order as requests even with async processing
*/
public class Netty4HttpPipeliningHandler extends ChannelDuplexHandler {
// Manages request/response ordering for HTTP pipelining
// Handles concurrent request processing with proper sequencing
}
/**
* HTTP header validation handler
* Validates headers according to HTTP specifications and security policies
*/
public class Netty4HttpHeaderValidator extends ChannelInboundHandlerAdapter {
// Validates HTTP headers for security and compliance
// Rejects malformed or dangerous header combinations
}The HTTP server transport provides comprehensive HTTP/1.1 support:
Content Encoding: Automatic gzip compression for large responses
Request Pipelining: Multiple concurrent requests on single connection
Keep-Alive: Connection reuse for improved performance
Content-Type Handling: JSON, YAML, CBOR, and other content types
CORS Support: Cross-origin resource sharing for web applications
Security Headers: Configurable security headers for enhanced protection
Request Size Limits: Configurable limits to prevent resource exhaustion
Timeout Management: Request and connection timeout handling
The HTTP transport integrates deeply with Elasticsearch's REST infrastructure:
Request Routing: Dispatches requests to appropriate REST handlers based on URL patterns
Content Negotiation: Handles different content types and response formats
Authentication Integration: Works with security plugins for request authentication
Rate Limiting: Integrates with circuit breakers and throttling mechanisms
Monitoring Integration: Provides detailed HTTP metrics and statistics
Error Handling: Converts internal exceptions to appropriate HTTP error responses
The HTTP transport serves as the primary interface for:
Install with Tessl CLI
npx tessl i tessl/maven-org-elasticsearch-plugin--transport-netty4-client