Core HTTP protocol support library for Eclipse Jetty providing header handling, parsing, generation, compliance validation, and content processing capabilities
npx @tessl/cli install tessl/maven-org-eclipse-jetty--jetty-http@12.0.0Jetty HTTP is the core HTTP protocol support library for Eclipse Jetty, providing comprehensive HTTP processing capabilities including header handling, parsing, generation, compliance validation, compression utilities, content management, and path mapping. It serves as the foundation for HTTP clients and servers with optimized performance and zero-copy buffer management.
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>12.0.21</version>
</dependency>import org.eclipse.jetty.http.*;
import org.eclipse.jetty.http.pathmap.*;
import org.eclipse.jetty.http.compression.*;
import org.eclipse.jetty.http.content.*;import org.eclipse.jetty.http.*;
// Create and manipulate HTTP headers
MutableHttpFields headers = new MutableHttpFields();
headers.put(HttpHeader.CONTENT_TYPE, "application/json");
headers.put(HttpHeader.CACHE_CONTROL, "no-cache");
// Parse HTTP method and status
HttpMethod method = HttpMethod.fromString("POST");
int statusCode = HttpStatus.OK_200;
// Handle URIs
HttpURI uri = HttpURI.from("https://example.com/api/users?id=123");
String host = uri.getHost(); // "example.com"
String path = uri.getPath(); // "/api/users"
String query = uri.getQuery(); // "id=123"
// Parse cookies
MutableHttpFields cookieHeaders = new MutableHttpFields();
cookieHeaders.add(HttpHeader.COOKIE, "session=abc123; user=john");
CookieCutter parser = new CookieCutter();
parser.parseFields(cookieHeaders);Jetty HTTP is organized around several key components:
HttpMethod, HttpStatus, HttpField, HttpFields)HttpParser, HttpGenerator)HttpURI, UriCompliance)HttpContent, HttpContent.Factory)PathSpec, ServletPathSpec, PathMappings)NBitIntegerEncoder, Huffman)Core HTTP header handling with optimized field collections, type-safe header enums, and efficient header value processing.
// Header field creation and manipulation
HttpField field = new HttpField(HttpHeader.CONTENT_TYPE, "application/json");
MutableHttpFields fields = new MutableHttpFields();
HttpField result = fields.put(HttpHeader.CACHE_CONTROL, "no-cache");
// Header collections interface
interface HttpFields extends Iterable<HttpField> {
int size();
HttpField getField(String name);
String get(HttpHeader header);
boolean contains(String name, String value);
Stream<HttpField> stream();
}Standard HTTP method and status code handling with safety and idempotency checks, efficient parsing, and caching.
// HTTP methods enumeration
enum HttpMethod {
GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, PATCH, CONNECT;
boolean isSafe();
boolean isIdempotent();
ByteBuffer asBuffer();
static HttpMethod fromString(String method);
}
// HTTP status codes and utilities
class HttpStatus {
static final int OK_200 = 200;
static final int NOT_FOUND_404 = 404;
static final int INTERNAL_SERVER_ERROR_500 = 500;
static String getMessage(int code);
static boolean isInformational(int code);
static boolean hasNoBody(int status);
}Comprehensive URI parsing, validation, and manipulation with compliance checking and efficient immutable/mutable patterns.
// URI interface and factories
interface HttpURI {
String getScheme();
String getHost();
int getPort();
String getPath();
String getQuery();
boolean isAbsolute();
static HttpURI.Immutable from(String uri);
static HttpURI.Mutable build(String uri);
}
// URI compliance validation
class UriCompliance {
static final UriCompliance DEFAULT;
static final UriCompliance LEGACY;
boolean allows(Violation violation);
}High-performance HTTP message parsing and generation with configurable compliance modes and efficient buffer management.
// HTTP parsing
class HttpParser {
HttpParser(RequestHandler requestHandler);
HttpParser(ResponseHandler responseHandler);
boolean parseNext(ByteBuffer buffer);
boolean isComplete();
void reset();
}
// HTTP generation
class HttpGenerator {
Result generateResponse(MetaData.Response info, boolean head,
ByteBuffer header, ByteBuffer chunk,
ByteBuffer content, boolean last);
boolean isEnd();
void reset();
}Complete cookie parsing and management with RFC compliance support and attribute handling.
// Cookie interface
interface HttpCookie {
String getName();
String getValue();
String getDomain();
String getPath();
boolean isSecure();
boolean isHttpOnly();
SameSite getSameSite();
static HttpCookie from(String name, String value);
}
// Cookie parsing
interface CookieParser {
void parseField(HttpField field);
void parseFields(HttpFields fields);
}Multi-part content handling for form data, file uploads, and byte ranges with async processing support.
// Multi-part content processing
class MultiPart {
String getBoundary();
List<Part> getParts();
Part getPart(String name);
interface Part {
String getName();
String getFileName();
HttpFields getHeaders();
Content.Source getContentSource();
}
}
// Form data processing
class MultiPartFormData {
CompletableFuture<Parts> parse(Content.Source source);
Parts from(Content.Source source);
}HTTP content handling with factory patterns, caching, compression support, and virtual file systems.
// Content interface
interface HttpContent {
HttpField getContentType();
HttpField getContentLength();
HttpField getLastModified();
HttpField getETag();
ByteBuffer getByteBuffer();
void release();
interface Factory {
HttpContent getContent(String path);
}
}
// Content factories
class ResourceHttpContentFactory implements HttpContent.Factory;
class CachingHttpContentFactory implements HttpContent.Factory;
class VirtualHttpContentFactory implements HttpContent.Factory;Flexible path specification matching for routing and dispatch with support for servlet-style, regex, and URI template patterns.
// Path specification interface
interface PathSpec extends Comparable<PathSpec> {
String getDeclaration();
boolean matches(String path);
MatchedPath matched(String path);
String getPathInfo(String path);
}
// Path mappings collection
class PathMappings<E> extends AbstractMap<PathSpec, E> {
MappedResource<E> getMatched(String path);
List<MappedResource<E>> getMatches(String path);
boolean put(PathSpec pathSpec, E resource);
}
// Servlet-style path specifications
class ServletPathSpec extends AbstractPathSpec {
ServletPathSpec(String servletPathSpec);
}HPACK compression utilities for HTTP/2 header compression including N-bit integer encoding and Huffman coding.
// N-bit integer encoding/decoding
class NBitIntegerEncoder {
static int octetsNeeded(int prefix, long value);
static void encode(ByteBuffer buffer, int prefix, long value);
}
class NBitIntegerDecoder {
void setPrefix(int prefix);
int decodeInt(ByteBuffer buffer);
long decodeLong(ByteBuffer buffer);
void reset();
}
// Huffman coding
class Huffman {
// Huffman encoding/decoding utilities
}// HTTP version enumeration
enum HttpVersion {
HTTP_0_9, HTTP_1_0, HTTP_1_1, HTTP_2_0, HTTP_3_0;
String asString();
int getVersion();
}
// HTTP scheme enumeration
enum HttpScheme {
HTTP, HTTPS, WS, WSS;
String asString();
int getDefaultPort();
}
// Metadata for requests and responses
class MetaData implements Iterable<HttpField> {
HttpURI getHttpURI();
HttpVersion getHttpVersion();
HttpFields getHttpFields();
static class Request extends MetaData;
static class Response extends MetaData;
}
// Compliance violation handling
interface ComplianceViolation {
interface Listener {
void onComplianceViolation(Mode mode, ComplianceViolation violation, String details);
}
enum Mode { COMPLIANCE, LEGACY, CUSTOM }
}
// Content processing interface
interface Content {
interface Source {
// Content source for streaming processing
}
interface Chunk {
ByteBuffer getByteBuffer();
boolean isLast();
}
}
// Exception types
class BadMessageException extends HttpException.RuntimeException;
class ComplianceViolationException extends IllegalArgumentException;
class EncodingException extends Exception;