HttpHeaderNames { public static AsciiString of(CharSequence name) { if (name instanceof AsciiString) { return of((AsciiString) name); } final String lowerCased = Ascii.toLowerCase(requireNonNull(name, "name")); final AsciiString cached = map.get(lowerCased); if (cached != null) { return cached; } return validate(AsciiString.cached(lowerCased)); } private  HttpHeaderNames(); static AsciiString of(CharSequence name); static AsciiString of(AsciiString name); static final AsciiString METHOD; static final AsciiString SCHEME; static final AsciiString AUTHORITY; static final AsciiString PATH; static final AsciiString STATUS; static final AsciiString CACHE_CONTROL; static final AsciiString CONTENT_LENGTH; static final AsciiString CONTENT_TYPE; static final AsciiString DATE; static final AsciiString PRAGMA; static final AsciiString VIA; static final AsciiString WARNING; static final AsciiString ACCEPT; static final AsciiString ACCEPT_CHARSET; static final AsciiString ACCEPT_ENCODING; static final AsciiString ACCEPT_LANGUAGE; static final AsciiString ACCESS_CONTROL_REQUEST_HEADERS; static final AsciiString ACCESS_CONTROL_REQUEST_METHOD; static final AsciiString AUTHORIZATION; static final AsciiString CONNECTION; static final AsciiString COOKIE; static final AsciiString EARLY_DATA; static final AsciiString EXPECT; static final AsciiString FROM; static final AsciiString FORWARDED; static final AsciiString FOLLOW_ONLY_WHEN_PRERENDER_SHOWN; static final AsciiString HOST; static final AsciiString HTTP2_SETTINGS; static final AsciiString IF_MATCH; static final AsciiString IF_MODIFIED_SINCE; static final AsciiString IF_NONE_MATCH; static final AsciiString IF_RANGE; static final AsciiString IF_UNMODIFIED_SINCE; static final AsciiString LAST_EVENT_ID; static final AsciiString MAX_FORWARDS; static final AsciiString ORIGIN; static final AsciiString PREFER; static final AsciiString PROXY_AUTHORIZATION; static final AsciiString RANGE; static final AsciiString REFERER; static final AsciiString REFERRER_POLICY; static final AsciiString SERVICE_WORKER; static final AsciiString TE; static final AsciiString UPGRADE; static final AsciiString USER_AGENT; static final AsciiString ACCEPT_RANGES; static final AsciiString ACCEPT_PATCH; static final AsciiString ACCESS_CONTROL_ALLOW_HEADERS; static final AsciiString ACCESS_CONTROL_ALLOW_METHODS; static final AsciiString ACCESS_CONTROL_ALLOW_ORIGIN; static final AsciiString ACCESS_CONTROL_ALLOW_CREDENTIALS; static final AsciiString ACCESS_CONTROL_EXPOSE_HEADERS; static final AsciiString ACCESS_CONTROL_MAX_AGE; static final AsciiString AGE; static final AsciiString ALLOW; static final AsciiString CONTENT_BASE; static final AsciiString CONTENT_DISPOSITION; static final AsciiString CONTENT_ENCODING; static final AsciiString CONTENT_LANGUAGE; static final AsciiString CONTENT_LOCATION; static final AsciiString CONTENT_MD5; static final AsciiString CONTENT_RANGE; static final AsciiString CONTENT_SECURITY_POLICY; static final AsciiString CONTENT_SECURITY_POLICY_REPORT_ONLY; static final AsciiString ETAG; static final AsciiString EXPIRES; static final AsciiString LAST_MODIFIED; static final AsciiString LINK; static final AsciiString LOCATION; static final AsciiString ORIGIN_TRIAL; static final AsciiString P3P; static final AsciiString PROXY_AUTHENTICATE; static final AsciiString REFRESH; static final AsciiString REPORT_TO; static final AsciiString RETRY_AFTER; static final AsciiString SERVER; static final AsciiString SERVER_TIMING; static final AsciiString SERVICE_WORKER_ALLOWED; static final AsciiString SET_COOKIE; static final AsciiString SET_COOKIE2; static final AsciiString SOURCE_MAP; static final AsciiString STRICT_TRANSPORT_SECURITY; static final AsciiString TIMING_ALLOW_ORIGIN; static final AsciiString TRAILER; static final AsciiString TRANSFER_ENCODING; static final AsciiString VARY; static final AsciiString WWW_AUTHENTICATE; static final AsciiString DNT; static final AsciiString X_CONTENT_TYPE_OPTIONS; static final AsciiString X_DO_NOT_TRACK; static final AsciiString X_FORWARDED_FOR; static final AsciiString X_FORWARDED_PROTO; static final AsciiString X_FORWARDED_HOST; static final AsciiString X_FORWARDED_PORT; static final AsciiString X_FRAME_OPTIONS; static final AsciiString X_POWERED_BY; static final AsciiString PUBLIC_KEY_PINS; static final AsciiString PUBLIC_KEY_PINS_REPORT_ONLY; static final AsciiString X_REQUESTED_WITH; static final AsciiString X_USER_IP; static final AsciiString X_DOWNLOAD_OPTIONS; static final AsciiString X_XSS_PROTECTION; static final AsciiString X_DNS_PREFETCH_CONTROL; static final AsciiString PING_FROM; static final AsciiString PING_TO; static final AsciiString SEC_TOKEN_BINDING; static final AsciiString SEC_PROVIDED_TOKEN_BINDING_ID; static final AsciiString SEC_REFERRED_TOKEN_BINDING_ID; }
@Test void testOfAsciiString() { final AsciiString mixedCased = AsciiString.of("Foo"); assertThat((Object) HttpHeaderNames.of(mixedCased)).isNotSameAs(mixedCased); assertThat(HttpHeaderNames.of(mixedCased).toString()).isEqualTo("foo"); final AsciiString lowerCased = AsciiString.of("foo"); assertThat((Object) HttpHeaderNames.of(lowerCased)).isSameAs(lowerCased); assertThat((Object) HttpHeaderNames.of(AsciiString.of("date"))).isSameAs(HttpHeaderNames.DATE); }
@Test void testOfCharSequence() { assertThat((Object) HttpHeaderNames.of("Foo")).isEqualTo(AsciiString.of("foo")); assertThat((Object) HttpHeaderNames.of("date")).isSameAs(HttpHeaderNames.DATE); }
@Test void pseudoHeaderNameValidation() { assertThat((Object) HttpHeaderNames.of(":method")).isSameAs(HttpHeaderNames.METHOD); assertThat((Object) HttpHeaderNames.of(":scheme")).isSameAs(HttpHeaderNames.SCHEME); assertThat((Object) HttpHeaderNames.of(":authority")).isSameAs(HttpHeaderNames.AUTHORITY); assertThat((Object) HttpHeaderNames.of(":path")).isSameAs(HttpHeaderNames.PATH); assertThat((Object) HttpHeaderNames.of(":status")).isSameAs(HttpHeaderNames.STATUS); assertThatThrownBy(() -> HttpHeaderNames.of(":foo")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: :foo"); }
@Test void headerNameValidation() { assertThatThrownBy(() -> HttpHeaderNames.of("")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: <EMPTY>"); assertThatThrownBy(() -> HttpHeaderNames.of("\u0000")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: <NUL>"); assertThatThrownBy(() -> HttpHeaderNames.of("\t")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: <TAB>"); assertThatThrownBy(() -> HttpHeaderNames.of("\n")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: <LF>"); assertThatThrownBy(() -> HttpHeaderNames.of("\u000B")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: <VT>"); assertThatThrownBy(() -> HttpHeaderNames.of("\f")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: <FF>"); assertThatThrownBy(() -> HttpHeaderNames.of("\r")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: <CR>"); assertThatThrownBy(() -> HttpHeaderNames.of(" ")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: <SP>"); assertThatThrownBy(() -> HttpHeaderNames.of(",")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: ,"); assertThatThrownBy(() -> HttpHeaderNames.of(":")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: :"); assertThatThrownBy(() -> HttpHeaderNames.of(";")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: ;"); assertThatThrownBy(() -> HttpHeaderNames.of("=")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("malformed header name: ="); }