Core HTTP protocol support library for Eclipse Jetty providing header handling, parsing, generation, compliance validation, and content processing capabilities
—
Comprehensive URI parsing, validation, and manipulation with compliance checking, efficient immutable/mutable patterns, and violation tracking.
Core URI interface with parsing, validation, and component access.
/**
* HTTP URI interface with immutable and mutable implementations
*/
interface HttpURI {
/** Get URI scheme (http, https, ws, wss) */
String getScheme();
/** Get host component */
String getHost();
/** Get port number (-1 if not specified) */
int getPort();
/** Get authority component (host:port) */
String getAuthority();
/** Get user info component */
String getUser();
/** Get raw path component */
String getPath();
/** Get normalized/canonical path */
String getCanonicalPath();
/** Get URL-decoded path */
String getDecodedPath();
/** Get last path parameter */
String getParam();
/** Get path with query string */
String getPathQuery();
/** Get query string component */
String getQuery();
/** Get fragment component */
String getFragment();
/** Check if URI is absolute (has scheme) */
boolean isAbsolute();
/** Check if URI has authority component */
boolean hasAuthority();
/** Check if URI has compliance violations */
boolean isAmbiguous();
/** Get detected compliance violations */
Set<UriCompliance.Violation> getViolations();
/** Convert to immutable URI */
Immutable asImmutable();
/** Get complete URI as string */
String asString();
/** Create mutable URI builder */
static Mutable build();
/** Parse URI string to mutable builder */
static Mutable build(String uri);
/** Parse URI string to immutable URI */
static Immutable from(String uri);
/** Convert java.net.URI to immutable URI */
static Immutable from(URI uri);
/** Build URI from components */
static Immutable from(String scheme, String host, int port, String pathQuery);
/**
* Immutable URI implementation
*/
interface Immutable extends HttpURI {
/** Convert to mutable builder */
Mutable mutable();
}
/**
* Mutable URI builder
*/
interface Mutable extends HttpURI {
/** Set URI scheme */
Mutable scheme(String scheme);
/** Set user info */
Mutable user(String user);
/** Set host */
Mutable host(String host);
/** Set port */
Mutable port(int port);
/** Set authority (host:port) */
Mutable authority(String authority);
/** Set path component */
Mutable path(String path);
/** Set path parameter */
Mutable param(String param);
/** Set query string */
Mutable query(String query);
/** Set fragment */
Mutable fragment(String fragment);
/** Set complete URI from string */
Mutable uri(String uri);
/** Set complete URI from java.net.URI */
Mutable uri(URI uri);
/** Build immutable URI */
Immutable asImmutable();
/** Clear all components */
void clear();
}
}URI compliance modes and violation handling.
/**
* URI compliance modes and validation
*/
class UriCompliance {
/** Default strict compliance */
static final UriCompliance DEFAULT;
/** Legacy compatibility mode */
static final UriCompliance LEGACY;
/** Unsafe character mode (allows more characters) */
static final UriCompliance UNSAFE;
/** Check if violation is allowed in this compliance mode */
boolean allows(Violation violation);
/** Get set of allowed violations */
Set<Violation> getAllowed();
/** Get compliance mode name */
String getName();
/**
* URI compliance violations
*/
enum Violation {
/** Ambiguous path separator */
AMBIGUOUS_PATH_SEPARATOR,
/** Ambiguous path segment */
AMBIGUOUS_PATH_SEGMENT,
/** Ambiguous path parameter */
AMBIGUOUS_PATH_PARAMETER,
/** Ambiguous empty segment */
AMBIGUOUS_EMPTY_SEGMENT,
/** UTF-8 not preferred encoding */
UTF8_NOT_PREFERRED,
/** Non-canonical ambiguous URI */
NON_CANONICAL_AMBIGUOUS_URI,
/** Suspicious path characters */
SUSPICIOUS_PATH_CHARACTERS;
}
}HTTP URI scheme handling with default ports.
/**
* HTTP URI schemes with default port handling
*/
enum HttpScheme {
/** HTTP scheme */
HTTP("http", 80),
/** HTTPS scheme */
HTTPS("https", 443),
/** WebSocket scheme */
WS("ws", 80),
/** Secure WebSocket scheme */
WSS("wss", 443);
/** Get scheme as string */
String asString();
/** Get default port for scheme */
int getDefaultPort();
/** Check if scheme matches string (case insensitive) */
boolean is(String scheme);
}Usage Examples:
import org.eclipse.jetty.http.*;
import java.net.URI;
// Parse URI from string
HttpURI.Immutable uri = HttpURI.from("https://example.com:8443/api/users?id=123&active=true#section1");
// Access URI components
String scheme = uri.getScheme(); // "https"
String host = uri.getHost(); // "example.com"
int port = uri.getPort(); // 8443
String authority = uri.getAuthority(); // "example.com:8443"
String path = uri.getPath(); // "/api/users"
String query = uri.getQuery(); // "id=123&active=true"
String fragment = uri.getFragment(); // "section1"
// Check URI properties
boolean absolute = uri.isAbsolute(); // true
boolean hasAuth = uri.hasAuthority(); // true
// Build URI with mutable builder
HttpURI.Mutable builder = HttpURI.build()
.scheme("https")
.host("api.example.com")
.port(443)
.path("/v1/users")
.query("limit=10&offset=20");
HttpURI.Immutable builtUri = builder.asImmutable();
String uriString = builtUri.asString(); // "https://api.example.com/v1/users?limit=10&offset=20"
// Parse with validation
HttpURI.Immutable parsedUri = HttpURI.from("/path/with spaces/file.txt");
boolean hasViolations = parsedUri.isAmbiguous();
Set<UriCompliance.Violation> violations = parsedUri.getViolations();
// Modify existing URI
HttpURI.Mutable modified = uri.mutable()
.path("/api/products")
.query("category=electronics")
.fragment(null);
// URI normalization and decoding
String canonical = uri.getCanonicalPath(); // Normalized path
String decoded = uri.getDecodedPath(); // URL-decoded path
// Convert from java.net.URI
URI javaUri = new URI("http://localhost:8080/app");
HttpURI.Immutable jettyUri = HttpURI.from(javaUri);
// Build from components
HttpURI.Immutable componentUri = HttpURI.from("http", "localhost", 8080, "/api/status");
// Working with compliance modes
UriCompliance strict = UriCompliance.DEFAULT;
UriCompliance lenient = UriCompliance.LEGACY;
boolean allowsSpaces = lenient.allows(UriCompliance.Violation.SUSPICIOUS_PATH_CHARACTERS);
// Check URI schemes
HttpScheme httpScheme = HttpScheme.HTTP;
int defaultPort = httpScheme.getDefaultPort(); // 80
boolean isHttps = HttpScheme.HTTPS.is("HTTPS"); // true (case insensitive)
// Path parameter handling
HttpURI.Immutable pathParamUri = HttpURI.from("/users;id=123/profile;edit=true");
String lastParam = pathParamUri.getParam(); // "edit=true"
// URI with user info
HttpURI.Immutable userUri = HttpURI.from("ftp://user:pass@ftp.example.com/files");
String userInfo = userUri.getUser(); // "user:pass"Install with Tessl CLI
npx tessl i tessl/maven-org-eclipse-jetty--jetty-http