001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http.classic; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021import java.net.*; 022import java.time.*; 023import java.util.*; 024import java.util.function.*; 025 026import org.apache.http.*; 027import org.apache.http.NameValuePair; 028import org.apache.juneau.commons.http.*; 029import org.apache.juneau.commons.lang.*; 030import org.apache.juneau.commons.reflect.*; 031import org.apache.juneau.http.classic.header.*; 032import org.apache.juneau.http.classic.header.Accept; 033import org.apache.juneau.http.classic.header.AcceptCharset; 034import org.apache.juneau.http.classic.header.AcceptEncoding; 035import org.apache.juneau.http.classic.header.AcceptLanguage; 036import org.apache.juneau.http.classic.header.AcceptRanges; 037import org.apache.juneau.http.classic.header.Age; 038import org.apache.juneau.http.classic.header.Allow; 039import org.apache.juneau.http.classic.header.Authorization; 040import org.apache.juneau.http.classic.header.CacheControl; 041import org.apache.juneau.http.classic.header.ClientVersion; 042import org.apache.juneau.http.classic.header.Connection; 043import org.apache.juneau.http.classic.header.ContentDisposition; 044import org.apache.juneau.http.classic.header.ContentEncoding; 045import org.apache.juneau.http.classic.header.ContentLanguage; 046import org.apache.juneau.http.classic.header.ContentLength; 047import org.apache.juneau.http.classic.header.ContentLocation; 048import org.apache.juneau.http.classic.header.ContentRange; 049import org.apache.juneau.http.classic.header.ContentType; 050import org.apache.juneau.http.classic.header.Date; 051import org.apache.juneau.http.classic.header.Debug; 052import org.apache.juneau.http.classic.header.ETag; 053import org.apache.juneau.http.classic.header.Expect; 054import org.apache.juneau.http.classic.header.Expires; 055import org.apache.juneau.http.classic.header.Forwarded; 056import org.apache.juneau.http.classic.header.From; 057import org.apache.juneau.http.classic.header.Host; 058import org.apache.juneau.http.classic.header.IfMatch; 059import org.apache.juneau.http.classic.header.IfModifiedSince; 060import org.apache.juneau.http.classic.header.IfNoneMatch; 061import org.apache.juneau.http.classic.header.IfRange; 062import org.apache.juneau.http.classic.header.IfUnmodifiedSince; 063import org.apache.juneau.http.classic.header.LastModified; 064import org.apache.juneau.http.classic.header.Location; 065import org.apache.juneau.http.classic.header.MaxForwards; 066import org.apache.juneau.http.classic.header.NoTrace; 067import org.apache.juneau.http.classic.header.Origin; 068import org.apache.juneau.http.classic.header.Pragma; 069import org.apache.juneau.http.classic.header.ProxyAuthenticate; 070import org.apache.juneau.http.classic.header.ProxyAuthorization; 071import org.apache.juneau.http.classic.header.Range; 072import org.apache.juneau.http.classic.header.Referer; 073import org.apache.juneau.http.classic.header.RetryAfter; 074import org.apache.juneau.http.classic.header.Server; 075import org.apache.juneau.http.classic.header.TE; 076import org.apache.juneau.http.classic.header.Thrown; 077import org.apache.juneau.http.classic.header.Trailer; 078import org.apache.juneau.http.classic.header.TransferEncoding; 079import org.apache.juneau.http.classic.header.Upgrade; 080import org.apache.juneau.http.classic.header.UserAgent; 081import org.apache.juneau.http.classic.header.Vary; 082import org.apache.juneau.http.classic.header.Via; 083import org.apache.juneau.http.classic.header.Warning; 084import org.apache.juneau.http.classic.header.WwwAuthenticate; 085import org.apache.juneau.http.classic.part.*; 086import org.apache.juneau.http.header.*; 087import org.apache.juneau.marshall.httppart.*; 088import org.apache.juneau.marshall.oapi.*; 089 090/** 091 * Standard predefined HTTP headers. 092 * 093 * <h5 class='section'>See Also:</h5><ul> 094 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommon">juneau-rest-common</a> 095 * </ul> 096 */ 097@SuppressWarnings({ 098 "java:S3740", // Raw Supplier/Header types used in factory methods where HTTP header value type cannot be statically parameterized 099 "java:S6539" // Monster class; HttpHeaders is intentionally a single static-factory facade, one creator method per standard HTTP header 100}) 101public class HttpHeaders { 102 103 /** 104 * Prevents instantiation. 105 */ 106 private HttpHeaders() {} 107 108 /** Accept header for <c>application/atom+xml</c>. */ 109 public static final Accept ACCEPT_APPLICATION_ATOM_XML = Accept.APPLICATION_ATOM_XML; 110 /** Accept header for <c>application/x-www-form-urlencoded</c>. */ 111 public static final Accept ACCEPT_APPLICATION_FORM_URLENCODED = Accept.APPLICATION_FORM_URLENCODED; 112 /** Accept header for <c>application/json</c>. */ 113 public static final Accept ACCEPT_APPLICATION_JSON = Accept.APPLICATION_JSON; 114 /** Accept header for <c>application/octet-stream</c>. */ 115 public static final Accept ACCEPT_APPLICATION_OCTET_STREAM = Accept.APPLICATION_OCTET_STREAM; 116 /** Accept header for <c>application/soap+xml</c>. */ 117 public static final Accept ACCEPT_APPLICATION_SOAP_XML = Accept.APPLICATION_SOAP_XML; 118 /** Accept header for <c>application/svg+xml</c>. */ 119 public static final Accept ACCEPT_APPLICATION_SVG_XML = Accept.APPLICATION_SVG_XML; 120 /** Accept header for <c>application/xhtml+xml</c>. */ 121 public static final Accept ACCEPT_APPLICATION_XHTML_XML = Accept.APPLICATION_XHTML_XML; 122 /** Accept header for <c>application/xml</c>. */ 123 public static final Accept ACCEPT_APPLICATION_XML = Accept.APPLICATION_XML; 124 /** Accept header for <c>image/bmp</c>. */ 125 public static final Accept ACCEPT_IMAGE_BMP = Accept.IMAGE_BMP; 126 /** Accept header for <c>image/gif</c>. */ 127 public static final Accept ACCEPT_IMAGE_GIF = Accept.IMAGE_GIF; 128 /** Accept header for <c>image/jpeg</c>. */ 129 public static final Accept ACCEPT_IMAGE_JPEG = Accept.IMAGE_JPEG; 130 /** Accept header for <c>image/png</c>. */ 131 public static final Accept ACCEPT_IMAGE_PNG = Accept.IMAGE_PNG; 132 /** Accept header for <c>image/svg+xml</c>. */ 133 public static final Accept ACCEPT_IMAGE_SVG = Accept.IMAGE_SVG; 134 /** Accept header for <c>image/tiff</c>. */ 135 public static final Accept ACCEPT_IMAGE_TIFF = Accept.IMAGE_TIFF; 136 /** Accept header for <c>image/webp</c>. */ 137 public static final Accept ACCEPT_IMAGE_WEBP = Accept.IMAGE_WEBP; 138 /** Accept header for <c>multipart/form-data</c>. */ 139 public static final Accept ACCEPT_MULTIPART_FORM_DATA = Accept.MULTIPART_FORM_DATA; 140 /** Accept header for <c>text/html</c>. */ 141 public static final Accept ACCEPT_TEXT_HTML = Accept.TEXT_HTML; 142 /** Accept header for <c>text/plain</c>. */ 143 public static final Accept ACCEPT_TEXT_PLAIN = Accept.TEXT_PLAIN; 144 /** Accept header for <c>text/xml</c>. */ 145 public static final Accept ACCEPT_TEXT_XML = Accept.TEXT_XML; 146 /** Accept header for <c>*/*</c> (all media types). */ 147 public static final Accept ACCEPT_WILDCARD = Accept.WILDCARD; 148 149 /** Content-Type for <c>application/atom+xml</c>. */ 150 public static final ContentType CONTENTTYPE_APPLICATION_ATOM_XML = ContentType.APPLICATION_ATOM_XML; 151 /** Content-Type for <c>application/x-www-form-urlencoded</c>. */ 152 public static final ContentType CONTENTTYPE_APPLICATION_FORM_URLENCODED = ContentType.APPLICATION_FORM_URLENCODED; 153 /** Content-Type for <c>application/json</c>. */ 154 public static final ContentType CONTENTTYPE_APPLICATION_JSON = ContentType.APPLICATION_JSON; 155 /** Content-Type for <c>application/octet-stream</c>. */ 156 public static final ContentType CONTENTTYPE_APPLICATION_OCTET_STREAM = ContentType.APPLICATION_OCTET_STREAM; 157 /** Content-Type for <c>application/soap+xml</c>. */ 158 public static final ContentType CONTENTTYPE_APPLICATION_SOAP_XML = ContentType.APPLICATION_SOAP_XML; 159 /** Content-Type for <c>application/svg+xml</c>. */ 160 public static final ContentType CONTENTTYPE_APPLICATION_SVG_XML = ContentType.APPLICATION_SVG_XML; 161 /** Content-Type for <c>application/xhtml+xml</c>. */ 162 public static final ContentType CONTENTTYPE_APPLICATION_XHTML_XML = ContentType.APPLICATION_XHTML_XML; 163 /** Content-Type for <c>application/xml</c>. */ 164 public static final ContentType CONTENTTYPE_APPLICATION_XML = ContentType.APPLICATION_XML; 165 /** Content-Type for <c>image/bmp</c>. */ 166 public static final ContentType CONTENTTYPE_IMAGE_BMP = ContentType.IMAGE_BMP; 167 /** Content-Type for <c>image/gif</c>. */ 168 public static final ContentType CONTENTTYPE_IMAGE_GIF = ContentType.IMAGE_GIF; 169 /** Content-Type for <c>image/jpeg</c>. */ 170 public static final ContentType CONTENTTYPE_IMAGE_JPEG = ContentType.IMAGE_JPEG; 171 /** Content-Type for <c>image/png</c>. */ 172 public static final ContentType CONTENTTYPE_IMAGE_PNG = ContentType.IMAGE_PNG; 173 /** Content-Type for <c>image/svg+xml</c>. */ 174 public static final ContentType CONTENTTYPE_IMAGE_SVG = ContentType.IMAGE_SVG; 175 /** Content-Type for <c>image/tiff</c>. */ 176 public static final ContentType CONTENTTYPE_IMAGE_TIFF = ContentType.IMAGE_TIFF; 177 /** Content-Type for <c>image/webp</c>. */ 178 public static final ContentType CONTENTTYPE_IMAGE_WEBP = ContentType.IMAGE_WEBP; 179 /** Content-Type for <c>multipart/form-data</c>. */ 180 public static final ContentType CONTENTTYPE_MULTIPART_FORM_DATA = ContentType.MULTIPART_FORM_DATA; 181 /** Content-Type for <c>text/html</c>. */ 182 public static final ContentType CONTENTTYPE_TEXT_HTML = ContentType.TEXT_HTML; 183 /** Content-Type for <c>text/plain</c>. */ 184 public static final ContentType CONTENTTYPE_TEXT_PLAIN = ContentType.TEXT_PLAIN; 185 /** Content-Type for <c>text/xml</c>. */ 186 public static final ContentType CONTENTTYPE_TEXT_XML = ContentType.TEXT_XML; 187 /** Content-Type for <c>*/*</c> (all media types). */ 188 public static final ContentType CONTENTTYPE_WILDCARD = ContentType.WILDCARD; 189 190 /** 191 * Creates a new {@link Accept} header. 192 * 193 * @param value 194 * The header value. 195 * <br>Can be <jk>null</jk>. 196 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 197 */ 198 public static final Accept accept(MediaRanges value) { 199 return Accept.of(value); 200 } 201 202 /** 203 * Creates a new {@link Accept} header. 204 * 205 * @param value 206 * The header value. 207 * <br>Can be <jk>null</jk>. 208 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 209 */ 210 public static final Accept accept(MediaType value) { 211 return Accept.of(value); 212 } 213 214 /** 215 * Creates a new {@link Accept} header. 216 * 217 * @param value 218 * The header value. 219 * <br>Must be parsable by {@link MediaRanges#of(String)}. 220 * <br>Can be <jk>null</jk>. 221 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 222 */ 223 public static final Accept accept(String value) { 224 return Accept.of(value); 225 } 226 227 /** 228 * Creates a new {@link Accept} header with a delayed value. 229 * 230 * <p> 231 * Header value is re-evaluated on each call to {@link Header#getValue()}. 232 * 233 * @param value 234 * The header value. 235 * <br>Can be <jk>null</jk>. 236 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 237 */ 238 public static final Accept accept(Supplier<MediaRanges> value) { 239 return Accept.of(value); 240 } 241 242 /** 243 * Creates a new {@link AcceptCharset} header. 244 * 245 * @param value 246 * The header value. 247 * <br>Must be parsable by {@link StringRanges#of(String)}. 248 * <br>Can be <jk>null</jk>. 249 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 250 */ 251 public static final AcceptCharset acceptCharset(String value) { 252 return AcceptCharset.of(value); 253 } 254 255 /** 256 * Creates a new {@link AcceptCharset} header. 257 * 258 * @param value 259 * The header value. 260 * <br>Can be <jk>null</jk>. 261 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 262 */ 263 public static final AcceptCharset acceptCharset(StringRanges value) { 264 return AcceptCharset.of(value); 265 } 266 267 /** 268 * Creates a new {@link AcceptCharset} header with a delayed value. 269 * 270 * <p> 271 * Header value is re-evaluated on each call to {@link Header#getValue()}. 272 * 273 * @param value 274 * The supplier of the header value. 275 * <br>Can be <jk>null</jk>. 276 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 277 */ 278 public static final AcceptCharset acceptCharset(Supplier<StringRanges> value) { 279 return AcceptCharset.of(value); 280 } 281 282 /** 283 * Creates a new {@link AcceptEncoding} header. 284 * 285 * @param value 286 * The header value. 287 * <br>Must be parsable by {@link StringRanges#of(String)}. 288 * <br>Can be <jk>null</jk>. 289 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 290 */ 291 public static final AcceptEncoding acceptEncoding(String value) { 292 return AcceptEncoding.of(value); 293 } 294 295 /** 296 * Creates a new {@link AcceptEncoding} header. 297 * 298 * @param value 299 * The header value. 300 * <br>Can be <jk>null</jk>. 301 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 302 */ 303 public static final AcceptEncoding acceptEncoding(StringRanges value) { 304 return AcceptEncoding.of(value); 305 } 306 307 /** 308 * Creates a new {@link AcceptEncoding} header with a delayed value. 309 * 310 * <p> 311 * Header value is re-evaluated on each call to {@link Header#getValue()}. 312 * 313 * @param value 314 * The supplier of the header value. 315 * <br>Can be <jk>null</jk>. 316 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 317 */ 318 public static final AcceptEncoding acceptEncoding(Supplier<StringRanges> value) { 319 return AcceptEncoding.of(value); 320 } 321 322 /** 323 * Creates a new {@link AcceptLanguage} header. 324 * 325 * @param value 326 * The header value. 327 * <br>Must be parsable by {@link StringRanges#of(String)}. 328 * <br>Can be <jk>null</jk>. 329 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 330 */ 331 public static final AcceptLanguage acceptLanguage(String value) { 332 return AcceptLanguage.of(value); 333 } 334 335 /** 336 * Creates a new {@link AcceptLanguage} header. 337 * 338 * @param value 339 * The header value. 340 * <br>Can be <jk>null</jk>. 341 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 342 */ 343 public static final AcceptLanguage acceptLanguage(StringRanges value) { 344 return AcceptLanguage.of(value); 345 } 346 347 /** 348 * Creates a new {@link AcceptLanguage} header with a delayed value. 349 * 350 * <p> 351 * Header value is re-evaluated on each call to {@link Header#getValue()}. 352 * 353 * @param value 354 * The supplier of the header value. 355 * <br>Can be <jk>null</jk>. 356 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 357 */ 358 public static final AcceptLanguage acceptLanguage(Supplier<StringRanges> value) { 359 return AcceptLanguage.of(value); 360 } 361 362 /** 363 * Creates a new {@link AcceptRanges} header. 364 * 365 * @param value 366 * The header value. 367 * <br>Can be <jk>null</jk>. 368 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 369 */ 370 public static final AcceptRanges acceptRanges(String value) { 371 return AcceptRanges.of(value); 372 } 373 374 /** 375 * Creates a new {@link AcceptRanges} header with a delayed value. 376 * 377 * <p> 378 * Header value is re-evaluated on each call to {@link Header#getValue()}. 379 * 380 * @param value 381 * The supplier of the header value. 382 * <br>Can be <jk>null</jk>. 383 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 384 */ 385 public static final AcceptRanges acceptRanges(Supplier<String> value) { 386 return AcceptRanges.of(value); 387 } 388 389 /** 390 * Creates a new {@link Age} header. 391 * 392 * @param value 393 * The header value. 394 * <br>Can be <jk>null</jk>. 395 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 396 */ 397 public static final Age age(Integer value) { 398 return Age.of(value); 399 } 400 401 /** 402 * Creates a new {@link Age} header. 403 * 404 * @param value 405 * The header value. 406 * <br>Must be parsable using {@link Integer#parseInt(String)}. 407 * <br>Can be <jk>null</jk>. 408 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 409 */ 410 public static final Age age(String value) { 411 return Age.of(value); 412 } 413 414 /** 415 * Creates a new {@link Age} header with a delayed value. 416 * 417 * <p> 418 * Header value is re-evaluated on each call to {@link Header#getValue()}. 419 * 420 * @param value 421 * The supplier of the header value. 422 * <br>Can be <jk>null</jk>. 423 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 424 */ 425 public static final Age age(Supplier<Integer> value) { 426 return Age.of(value); 427 } 428 429 /** 430 * Creates a new {@link Allow} header. 431 * 432 * @param value 433 * The header value. 434 * <br>Can be <jk>null</jk>. 435 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 436 */ 437 public static final Allow allow(String value) { 438 return Allow.of(value); 439 } 440 441 /** 442 * Creates a new {@link Allow} header. 443 * 444 * @param value 445 * The header value. 446 * <br>Can be <jk>null</jk>. 447 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 448 */ 449 public static final Allow allow(String...value) { 450 return Allow.of(value); 451 } 452 453 /** 454 * Creates a new {@link Allow} header with a delayed value. 455 * 456 * <p> 457 * Header value is re-evaluated on each call to {@link Header#getValue()}. 458 * 459 * @param value 460 * The supplier of the header value. 461 * <br>Can be <jk>null</jk>. 462 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 463 */ 464 public static final Allow allow(Supplier<String[]> value) { 465 return Allow.of(value); 466 } 467 468 /** 469 * Creates a new {@link Authorization} header. 470 * 471 * @param value 472 * The header value. 473 * <br>Can be <jk>null</jk>. 474 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 475 */ 476 public static final Authorization authorization(String value) { 477 return Authorization.of(value); 478 } 479 480 /** 481 * Creates a new {@link Authorization} header with a delayed value. 482 * 483 * <p> 484 * Header value is re-evaluated on each call to {@link Header#getValue()}. 485 * 486 * @param value 487 * The supplier of the header value. 488 * <br>Can be <jk>null</jk>. 489 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 490 */ 491 public static final Authorization authorization(Supplier<String> value) { 492 return Authorization.of(value); 493 } 494 495 /** 496 * Creates a new {@link BasicHeader} header. 497 * 498 * @param name The parameter name. 499 * @param value 500 * The parameter value. 501 * <br>Can be <jk>null</jk>. 502 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 503 */ 504 public static final BasicHeader basicHeader(String name, Object value) { 505 return BasicHeader.of(name, value); 506 } 507 508 /** 509 * Creates a new {@link BasicHeader} header with a delayed value. 510 * 511 * <p> 512 * Header value is re-evaluated on each call to {@link Header#getValue()}. 513 * 514 * @param name The header name. 515 * @param value 516 * The supplier of the header value. 517 * <br>Can be <jk>null</jk> to create a header with no value. 518 * @return A new header bean. Never <jk>null</jk>. 519 * @throws IllegalArgumentException If name is <jk>null</jk> or empty. 520 */ 521 public static final BasicHeader basicHeader(String name, Supplier<?> value) { 522 return new BasicHeader(name, value); 523 } 524 525 /** 526 * Creates a new {@link BasicBooleanHeader} header. 527 * 528 * @param name The header name. 529 * @param value 530 * The header value. 531 * <br>Can be <jk>null</jk>. 532 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 533 */ 534 public static final BasicBooleanHeader booleanHeader(String name, Boolean value) { 535 return BasicBooleanHeader.of(name, value); 536 } 537 538 /** 539 * Creates a new {@link BasicBooleanHeader} header. 540 * 541 * @param name The header name. 542 * @param value 543 * The header value. 544 * <br>Must be parsable by {@link Boolean#parseBoolean(String)}. 545 * <br>Can be <jk>null</jk>. 546 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 547 */ 548 public static final BasicBooleanHeader booleanHeader(String name, String value) { 549 return BasicBooleanHeader.of(name, value); 550 } 551 552 /** 553 * Creates a new {@link BasicBooleanHeader} header with a delayed value. 554 * 555 * <p> 556 * Header value is re-evaluated on each call to {@link Header#getValue()}. 557 * 558 * @param name The header name. 559 * @param value 560 * The supplier of the header value. 561 * <br>Can be <jk>null</jk>. 562 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 563 */ 564 public static final BasicBooleanHeader booleanHeader(String name, Supplier<Boolean> value) { 565 return BasicBooleanHeader.of(name, value); 566 } 567 568 /** 569 * Creates a new {@link CacheControl} header. 570 * 571 * @param value 572 * The header value. 573 * <br>Can be <jk>null</jk>. 574 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 575 */ 576 public static final CacheControl cacheControl(String value) { 577 return CacheControl.of(value); 578 } 579 580 /** 581 * Creates a new {@link CacheControl} header with a delayed value. 582 * 583 * <p> 584 * Header value is re-evaluated on each call to {@link Header#getValue()}. 585 * 586 * @param value 587 * The supplier of the header value. 588 * <br>Can be <jk>null</jk>. 589 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 590 */ 591 public static final CacheControl cacheControl(Supplier<String> value) { 592 return CacheControl.of(value); 593 } 594 595 /** 596 * Returns <jk>true</jk> if the {@link #cast(Object)} method can be used on the specified object. 597 * 598 * @param o The object to check. 599 * @return <jk>true</jk> if the {@link #cast(Object)} method can be used on the specified object. 600 */ 601 public static boolean canCast(Object o) { 602 if (o == null) 603 return false; 604 var ci = ClassInfo.of(o); 605 return nn(ci) && ci.isAssignableToAny(Header.class, Headerable.class, NameValuePair.class, NameValuePairable.class, Map.Entry.class); 606 } 607 608 /** 609 * Utility method for converting an arbitrary object to a {@link Header}. 610 * 611 * @param o 612 * The object to cast or convert to a {@link Header}. 613 * @return Either the same object cast as a {@link Header} or converted to a {@link Header}. 614 */ 615 @SuppressWarnings({ 616 "java:S2681" // Each if-branch has a single return; indentation mismatch is cosmetic, not a logic error 617 }) 618 public static Header cast(Object o) { 619 if (o instanceof Header o2) 620 return o2; 621 if (o instanceof Headerable o2) 622 return o2.asHeader(); 623 if (o instanceof NameValuePair o2) 624 return BasicHeader.of(o2); 625 if (o instanceof NameValuePairable o2) 626 return BasicHeader.of(o2.asNameValuePair()); 627 if (o instanceof Map.Entry e) { 628 return BasicHeader.of(s(e.getKey()), s(e.getValue())); 629 } 630 throw rex("Object of type %s could not be converted to a Header.", cn(o)); 631 } 632 633 /** 634 * Creates a new {@link ClientVersion} header. 635 * 636 * @param value 637 * The header value. 638 * <br>Must be parsable by {@link Version#of(String)} 639 * <br>Can be <jk>null</jk>. 640 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 641 */ 642 public static final ClientVersion clientVersion(String value) { 643 return ClientVersion.of(value); 644 } 645 646 /** 647 * Creates a new {@link ClientVersion} header with a delayed value. 648 * 649 * <p> 650 * Header value is re-evaluated on each call to {@link Header#getValue()}. 651 * 652 * @param value 653 * The supplier of the header value. 654 * <br>Can be <jk>null</jk>. 655 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 656 */ 657 public static final ClientVersion clientVersion(Supplier<Version> value) { 658 return ClientVersion.of(value); 659 } 660 661 /** 662 * Creates a new {@link ClientVersion} header. 663 * 664 * @param value 665 * The header value. 666 * <br>Can be <jk>null</jk>. 667 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 668 */ 669 public static final ClientVersion clientVersion(Version value) { 670 return ClientVersion.of(value); 671 } 672 673 /** 674 * Creates a new {@link Connection} header. 675 * 676 * @param value 677 * The header value. 678 * <br>Can be <jk>null</jk>. 679 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 680 */ 681 public static final Connection connection(String value) { 682 return Connection.of(value); 683 } 684 685 /** 686 * Creates a new {@link Connection} header with a delayed value. 687 * 688 * <p> 689 * Header value is re-evaluated on each call to {@link Header#getValue()}. 690 * 691 * @param value 692 * The supplier of the header value. 693 * <br>Can be <jk>null</jk>. 694 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 695 */ 696 public static final Connection connection(Supplier<String> value) { 697 return Connection.of(value); 698 } 699 700 /** 701 * Creates a new {@link ContentDisposition} header. 702 * 703 * @param value 704 * The header value. 705 * <br>Must be parsable by {@link StringRanges#of(String)}. 706 * <br>Can be <jk>null</jk>. 707 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 708 */ 709 public static final ContentDisposition contentDisposition(String value) { 710 return ContentDisposition.of(value); 711 } 712 713 /** 714 * Creates a new {@link ContentDisposition} header. 715 * 716 * @param value 717 * The header value. 718 * <br>Can be <jk>null</jk>. 719 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 720 */ 721 public static final ContentDisposition contentDisposition(StringRanges value) { 722 return ContentDisposition.of(value); 723 } 724 725 /** 726 * Creates a new {@link ContentDisposition} header with a delayed value. 727 * 728 * <p> 729 * Header value is re-evaluated on each call to {@link Header#getValue()}. 730 * 731 * @param value 732 * The supplier of the header value. 733 * <br>Can be <jk>null</jk>. 734 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 735 */ 736 public static final ContentDisposition contentDisposition(Supplier<StringRanges> value) { 737 return ContentDisposition.of(value); 738 } 739 740 /** 741 * Creates a {@link ContentDisposition} header for a response attachment with a quoted {@code filename} parameter. 742 * 743 * <p> 744 * Equivalent to {@link ContentDisposition#attachment(String)}. 745 * </p> 746 * 747 * @param filename Suggested download name. Must not be <jk>null</jk>, blank, or contain CR/LF. 748 * @return A non-<jk>null</jk> header. 749 * @throws IllegalArgumentException If {@code filename} is invalid. 750 */ 751 public static final ContentDisposition contentDispositionAttachment(String filename) { 752 return ContentDisposition.attachment(filename); 753 } 754 755 /** 756 * Creates a new {@link ContentEncoding} header. 757 * 758 * @param value 759 * The header value. 760 * <br>Can be <jk>null</jk>. 761 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 762 */ 763 public static final ContentEncoding contentEncoding(String value) { 764 return ContentEncoding.of(value); 765 } 766 767 /** 768 * Creates a new {@link ContentEncoding} header with a delayed value. 769 * 770 * <p> 771 * Header value is re-evaluated on each call to {@link Header#getValue()}. 772 * 773 * @param value 774 * The supplier of the header value. 775 * <br>Can be <jk>null</jk>. 776 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 777 */ 778 public static final ContentEncoding contentEncoding(Supplier<String> value) { 779 return ContentEncoding.of(value); 780 } 781 782 /** 783 * Creates a new {@link ContentLanguage} header. 784 * 785 * @param value 786 * The header value. 787 * <br>Can be <jk>null</jk>. 788 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 789 */ 790 public static final ContentLanguage contentLanguage(String value) { 791 return ContentLanguage.of(value); 792 } 793 794 /** 795 * Creates a new {@link ContentLanguage} header. 796 * 797 * @param value 798 * The header value. 799 * <br>Can be <jk>null</jk>. 800 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 801 */ 802 public static final ContentLanguage contentLanguage(String...value) { 803 return ContentLanguage.of(value); 804 } 805 806 /** 807 * Creates a new {@link ContentLanguage} header with a delayed value. 808 * 809 * <p> 810 * Header value is re-evaluated on each call to {@link Header#getValue()}. 811 * 812 * @param value 813 * The supplier of the header value. 814 * <br>Can be <jk>null</jk>. 815 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 816 */ 817 public static final ContentLanguage contentLanguage(Supplier<String[]> value) { 818 return ContentLanguage.of(value); 819 } 820 821 /** 822 * Creates a new {@link ContentLength} header. 823 * 824 * @param value 825 * The header value. 826 * <br>Can be <jk>null</jk>. 827 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 828 */ 829 public static final ContentLength contentLength(Long value) { 830 return ContentLength.of(value); 831 } 832 833 /** 834 * Creates a new {@link ContentLength} header. 835 * 836 * @param value 837 * The header value. 838 * <br>Must be parsable using {@link Long#parseLong(String)}. 839 * <br>Can be <jk>null</jk>. 840 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 841 */ 842 public static final ContentLength contentLength(String value) { 843 return ContentLength.of(value); 844 } 845 846 /** 847 * Creates a new {@link ContentLength} header with a delayed value. 848 * 849 * <p> 850 * Header value is re-evaluated on each call to {@link Header#getValue()}. 851 * 852 * @param value 853 * The supplier of the header value. 854 * <br>Can be <jk>null</jk>. 855 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 856 */ 857 public static final ContentLength contentLength(Supplier<Long> value) { 858 return ContentLength.of(value); 859 } 860 861 /** 862 * Creates a new {@link ContentLocation} header. 863 * 864 * @param value 865 * The header value. 866 * <br>Must be parsable by {@link URI#create(String)}. 867 * <br>Can be <jk>null</jk>. 868 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 869 */ 870 public static final ContentLocation contentLocation(String value) { 871 return ContentLocation.of(value); 872 } 873 874 /** 875 * Creates a new {@link ContentLocation} header with a delayed value. 876 * 877 * <p> 878 * Header value is re-evaluated on each call to {@link Header#getValue()}. 879 * 880 * @param value 881 * The supplier of the header value. 882 * <br>Can be <jk>null</jk>. 883 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 884 */ 885 public static final ContentLocation contentLocation(Supplier<URI> value) { 886 return ContentLocation.of(value); 887 } 888 889 /** 890 * Creates a new {@link ContentLocation} header. 891 * 892 * @param value 893 * The header value. 894 * <br>Can be <jk>null</jk>. 895 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 896 */ 897 public static final ContentLocation contentLocation(URI value) { 898 return ContentLocation.of(value); 899 } 900 901 /** 902 * Creates a new {@link ContentRange} header. 903 * 904 * @param value 905 * The header value. 906 * <br>Can be <jk>null</jk>. 907 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 908 */ 909 public static final ContentRange contentRange(String value) { 910 return ContentRange.of(value); 911 } 912 913 /** 914 * Creates a new {@link ContentRange} header with a delayed value. 915 * 916 * <p> 917 * Header value is re-evaluated on each call to {@link Header#getValue()}. 918 * 919 * @param value 920 * The supplier of the header value. 921 * <br>Can be <jk>null</jk>. 922 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 923 */ 924 public static final ContentRange contentRange(Supplier<String> value) { 925 return ContentRange.of(value); 926 } 927 928 /** 929 * Creates a new {@link ContentType} header. 930 * 931 * @param value 932 * The header value. 933 * <br>Can be <jk>null</jk>. 934 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 935 */ 936 public static final ContentType contentType(MediaType value) { 937 return ContentType.of(value); 938 } 939 940 /** 941 * Creates a new {@link ContentType} header. 942 * 943 * @param value 944 * The header value. 945 * <br>Must be parsable by {@link MediaType#of(String)}. 946 * <br>Can be <jk>null</jk>. 947 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 948 */ 949 public static final ContentType contentType(String value) { 950 return ContentType.of(value); 951 } 952 953 /** 954 * Creates a new {@link ContentType} header with a delayed value. 955 * 956 * <p> 957 * Header value is re-evaluated on each call to {@link Header#getValue()}. 958 * 959 * @param value 960 * The header value. 961 * <br>Can be <jk>null</jk>. 962 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 963 */ 964 public static final ContentType contentType(Supplier<MediaType> value) { 965 return ContentType.of(value); 966 } 967 968 /** 969 * Creates a new {@link BasicCsvHeader} header. 970 * 971 * @param name The header name. 972 * @param value 973 * The header value. 974 * <br>Must be a comma-delimited list. 975 * <br>Can be <jk>null</jk>. 976 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 977 */ 978 public static final BasicCsvHeader csvHeader(String name, String value) { 979 return BasicCsvHeader.of(name, value); 980 } 981 982 /** 983 * Creates a new {@link BasicCsvHeader} header. 984 * 985 * @param name The header name. 986 * @param value 987 * The header value. 988 * <br>Can be <jk>null</jk>. 989 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 990 */ 991 public static final BasicCsvHeader csvHeader(String name, String...value) { 992 return BasicCsvHeader.of(name, value); 993 } 994 995 /** 996 * Creates a new {@link BasicCsvHeader} header with a delayed value. 997 * 998 * <p> 999 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1000 * 1001 * @param name The header name. 1002 * @param value 1003 * The supplier of the header value. 1004 * <br>Can be <jk>null</jk>. 1005 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1006 */ 1007 public static final BasicCsvHeader csvHeader(String name, Supplier<String[]> value) { 1008 return BasicCsvHeader.of(name, value); 1009 } 1010 1011 /** 1012 * Creates a new {@link Date} header. 1013 * 1014 * @param value 1015 * The header value. 1016 * <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 1017 * <br>Can be <jk>null</jk>. 1018 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1019 */ 1020 public static final Date date(String value) { 1021 return Date.of(value); 1022 } 1023 1024 /** 1025 * Creates a new {@link Date} header with a delayed value. 1026 * 1027 * <p> 1028 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1029 * 1030 * @param value 1031 * The supplier of the header value. 1032 * <br>Can be <jk>null</jk>. 1033 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1034 */ 1035 public static final Date date(Supplier<ZonedDateTime> value) { 1036 return Date.of(value); 1037 } 1038 1039 /** 1040 * Creates a new {@link Date} header. 1041 * 1042 * @param value 1043 * The header value. 1044 * <br>Can be <jk>null</jk>. 1045 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1046 */ 1047 public static final Date date(ZonedDateTime value) { 1048 return Date.of(value); 1049 } 1050 1051 /** 1052 * Creates a new {@link BasicDateHeader} header. 1053 * 1054 * @param name The header name. 1055 * @param value 1056 * The header value. 1057 * <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 1058 * <br>Can be <jk>null</jk>. 1059 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1060 */ 1061 public static final BasicDateHeader dateHeader(String name, String value) { 1062 return BasicDateHeader.of(name, value); 1063 } 1064 1065 /** 1066 * Creates a new {@link BasicDateHeader} header with a delayed value. 1067 * 1068 * <p> 1069 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1070 * 1071 * @param name The header name. 1072 * @param value 1073 * The supplier of the header value. 1074 * <br>Can be <jk>null</jk>. 1075 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1076 */ 1077 public static final BasicDateHeader dateHeader(String name, Supplier<ZonedDateTime> value) { 1078 return BasicDateHeader.of(name, value); 1079 } 1080 1081 /** 1082 * Creates a new {@link BasicDateHeader} header. 1083 * 1084 * @param name The header name. 1085 * @param value 1086 * The header value. 1087 * <br>Can be <jk>null</jk>. 1088 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1089 */ 1090 public static final BasicDateHeader dateHeader(String name, ZonedDateTime value) { 1091 return BasicDateHeader.of(name, value); 1092 } 1093 1094 /** 1095 * Creates a new {@link Debug} header. 1096 * 1097 * @param value 1098 * The header value. 1099 * <br>Must be parsable by {@link Boolean#parseBoolean(String)}. 1100 * <br>Can be <jk>null</jk>. 1101 * @return A new header bean, or <jk>null</jk> if the value was <jk>null</jk>. 1102 */ 1103 public static final Debug debug(Boolean value) { 1104 return Debug.of(value); 1105 } 1106 1107 /** 1108 * Creates a new {@link Debug} header. 1109 * 1110 * @param value 1111 * The header value. 1112 * <br>Must be parsable by {@link Boolean#parseBoolean(String)}. 1113 * <br>Can be <jk>null</jk>. 1114 * @return A new header bean, or <jk>null</jk> if the value was <jk>null</jk>. 1115 */ 1116 public static final Debug debug(String value) { 1117 return Debug.of(value); 1118 } 1119 1120 /** 1121 * Creates a new {@link Debug} header with a delayed value. 1122 * 1123 * <p> 1124 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1125 * 1126 * @param value 1127 * The header value supplier. 1128 * <br>Can be <jk>null</jk>. 1129 * @return A new header bean, or <jk>null</jk> if the value was <jk>null</jk>. 1130 */ 1131 public static final Debug debug(Supplier<Boolean> value) { 1132 return Debug.of(value); 1133 } 1134 1135 /** 1136 * Creates a new {@link BasicEntityTagHeader} header. 1137 * 1138 * @param name The header name. 1139 * @param value 1140 * The header value. 1141 * <br>Can be <jk>null</jk>. 1142 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1143 */ 1144 public static final BasicEntityTagHeader entityTagHeader(String name, EntityTag value) { 1145 return BasicEntityTagHeader.of(name, value); 1146 } 1147 1148 /** 1149 * Creates a new {@link BasicEntityTagHeader} header. 1150 * 1151 * @param name The header name. 1152 * @param value 1153 * The header value. 1154 * <br>Must be an entity tag value (e.g. <js>"\"xyzzy\""</js>). 1155 * <br>Can be <jk>null</jk>. 1156 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1157 */ 1158 public static final BasicEntityTagHeader entityTagHeader(String name, String value) { 1159 return BasicEntityTagHeader.of(name, value); 1160 } 1161 1162 /** 1163 * Creates a new {@link BasicEntityTagHeader} header with a delayed value. 1164 * 1165 * <p> 1166 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1167 * 1168 * @param name The header name. 1169 * @param value 1170 * The supplier of the header value. 1171 * <br>Can be <jk>null</jk>. 1172 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1173 */ 1174 public static final BasicEntityTagHeader entityTagHeader(String name, Supplier<EntityTag> value) { 1175 return BasicEntityTagHeader.of(name, value); 1176 } 1177 1178 /** 1179 * Creates a new {@link BasicEntityTagsHeader} header. 1180 * 1181 * @param name The header name. 1182 * @param value 1183 * The header value. 1184 * <br>Can be <jk>null</jk>. 1185 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1186 */ 1187 public static final BasicEntityTagsHeader entityTagsHeader(String name, EntityTags value) { 1188 return BasicEntityTagsHeader.of(name, value); 1189 } 1190 1191 /** 1192 * Creates a new {@link BasicEntityTagsHeader} header. 1193 * 1194 * @param name The header name. 1195 * @param value 1196 * The header value. 1197 * <br>Must be a comma-delimited list of entity validator values (e.g. <js>"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""</js>). 1198 * <br>Can be <jk>null</jk>. 1199 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1200 */ 1201 public static final BasicEntityTagsHeader entityTagsHeader(String name, String value) { 1202 return BasicEntityTagsHeader.of(name, value); 1203 } 1204 1205 /** 1206 * Creates a new {@link BasicEntityTagsHeader} header with a delayed value. 1207 * 1208 * <p> 1209 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1210 * 1211 * @param name The header name. 1212 * @param value 1213 * The supplier of the header value. 1214 * <br>Can be <jk>null</jk>. 1215 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1216 */ 1217 public static final BasicEntityTagsHeader entityTagsHeader(String name, Supplier<EntityTags> value) { 1218 return BasicEntityTagsHeader.of(name, value); 1219 } 1220 1221 /** 1222 * Creates a new {@link ETag} header. 1223 * 1224 * @param value 1225 * The header value. 1226 * <br>Can be <jk>null</jk>. 1227 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1228 */ 1229 public static final ETag eTag(EntityTag value) { 1230 return ETag.of(value); 1231 } 1232 1233 /** 1234 * Creates a new {@link ETag} header. 1235 * 1236 * @param value 1237 * The header value. 1238 * <br>Must be an entity tag value (e.g. <js>"\"xyzzy\""</js>). 1239 * <br>Can be <jk>null</jk>. 1240 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1241 */ 1242 public static final ETag eTag(String value) { 1243 return ETag.of(value); 1244 } 1245 1246 /** 1247 * Creates a new {@link ETag} header with a delayed value. 1248 * 1249 * <p> 1250 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1251 * 1252 * @param value 1253 * The supplier of the header value. 1254 * <br>Can be <jk>null</jk>. 1255 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1256 */ 1257 public static final ETag eTag(Supplier<EntityTag> value) { 1258 return ETag.of(value); 1259 } 1260 1261 /** 1262 * Creates a new {@link Expect} header. 1263 * 1264 * @param value 1265 * The header value. 1266 * <br>Can be <jk>null</jk>. 1267 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1268 */ 1269 public static final Expect expect(String value) { 1270 return Expect.of(value); 1271 } 1272 1273 /** 1274 * Creates a new {@link Expect} header with a delayed value. 1275 * 1276 * <p> 1277 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1278 * 1279 * @param value 1280 * The supplier of the header value. 1281 * <br>Can be <jk>null</jk>. 1282 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1283 */ 1284 public static final Expect expect(Supplier<String> value) { 1285 return Expect.of(value); 1286 } 1287 1288 /** 1289 * Creates a new {@link Expires} header. 1290 * 1291 * @param value 1292 * The header value. 1293 * <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 1294 * <br>Can be <jk>null</jk>. 1295 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1296 */ 1297 public static final Expires expires(String value) { 1298 return Expires.of(value); 1299 } 1300 1301 /** 1302 * Creates a new {@link Expires} header with a delayed value. 1303 * 1304 * <p> 1305 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1306 * 1307 * @param value 1308 * The supplier of the header value. 1309 * <br>Can be <jk>null</jk>. 1310 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1311 */ 1312 public static final Expires expires(Supplier<ZonedDateTime> value) { 1313 return Expires.of(value); 1314 } 1315 1316 /** 1317 * Creates a new {@link Expires} header. 1318 * 1319 * @param value 1320 * The header value. 1321 * <br>Can be <jk>null</jk>. 1322 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1323 */ 1324 public static final Expires expires(ZonedDateTime value) { 1325 return Expires.of(value); 1326 } 1327 1328 /** 1329 * Creates a new {@link Forwarded} header. 1330 * 1331 * @param value 1332 * The header value. 1333 * <br>Can be <jk>null</jk>. 1334 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1335 */ 1336 public static final Forwarded forwarded(String value) { 1337 return Forwarded.of(value); 1338 } 1339 1340 /** 1341 * Creates a new {@link Forwarded} header with a delayed value. 1342 * 1343 * <p> 1344 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1345 * 1346 * @param value 1347 * The supplier of the header value. 1348 * <br>Can be <jk>null</jk>. 1349 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1350 */ 1351 public static final Forwarded forwarded(Supplier<String> value) { 1352 return Forwarded.of(value); 1353 } 1354 1355 /** 1356 * Creates a new {@link From} header. 1357 * 1358 * @param value 1359 * The header value. 1360 * <br>Can be <jk>null</jk>. 1361 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1362 */ 1363 public static final From from(String value) { 1364 return From.of(value); 1365 } 1366 1367 /** 1368 * Creates a new {@link From} header with a delayed value. 1369 * 1370 * <p> 1371 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1372 * 1373 * @param value 1374 * The supplier of the header value. 1375 * <br>Can be <jk>null</jk>. 1376 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1377 */ 1378 public static final From from(Supplier<String> value) { 1379 return From.of(value); 1380 } 1381 1382 /** 1383 * Creates a new {@link Header} of the specified type. 1384 * 1385 * <p> 1386 * Same as {@link #header(Class, String, Object)} but the header name is pulled from the {@link org.apache.juneau.http.Header#name() @Header(name)} or 1387 * {@link org.apache.juneau.http.Header#value() @Header(value)} annotations. 1388 * 1389 * @param <T> The header implementation class. 1390 * @param type The header implementation class. Must not be <jk>null</jk>. 1391 * @param value The header value. Can be <jk>null</jk>, in which case it is passed as-is (or stringified to <jk>null</jk>) to the bean's constructor. 1392 * @return A new unmodifiable instance, never <jk>null</jk>. 1393 */ 1394 public static final <T extends Header> T header(Class<T> type, Object value) { 1395 return HeaderBeanMeta.of(type).construct(null, value); 1396 } 1397 1398 /** 1399 * Creates a new {@link Header} of the specified type. 1400 * 1401 * <p> 1402 * The implementation class must have a public constructor taking in one of the following argument lists: 1403 * <ul> 1404 * <li><c><jk>public</jk> X(String <jv>headerValue</jv>)</c> 1405 * <li><c><jk>public</jk> X(Object <jv>headerValue</jv>)</c> 1406 * <li><c><jk>public</jk> X(String <jv>headerName</jv>, String <jv>headerValue</jv>)</c> 1407 * <li><c><jk>public</jk> X(String <jv>headerName</jv>, Object <jv>headerValue</jv>)</c> 1408 * </ul> 1409 * 1410 * @param <T> The header implementation class. 1411 * @param type The header implementation class. Must not be <jk>null</jk>. 1412 * @param name The header name. Can be <jk>null</jk> to use the name from the {@link org.apache.juneau.http.Header @Header} annotation. 1413 * @param value The header value. Can be <jk>null</jk>, in which case it is passed as-is (or stringified to <jk>null</jk>) to the bean's constructor. 1414 * @return A new unmodifiable instance, never <jk>null</jk>. 1415 */ 1416 public static final <T extends Header> T header(Class<T> type, String name, Object value) { 1417 return HeaderBeanMeta.of(type).construct(name, value); 1418 } 1419 1420 /** 1421 * Instantiates a new {@link HeaderList}. 1422 * 1423 * @return A new empty builder. 1424 */ 1425 public static final HeaderList headerList() { 1426 return HeaderList.create(); 1427 } 1428 1429 /** 1430 * Creates a new {@link HeaderList} initialized with the specified headers. 1431 * 1432 * @param headers The headers to add to the list. Can be <jk>null</jk>. <jk>null</jk> entries are ignored. 1433 * @return A new unmodifiable instance, never <jk>null</jk>. 1434 */ 1435 public static final HeaderList headerList(Header...headers) { 1436 return HeaderList.of(headers); 1437 } 1438 1439 /** 1440 * Creates a new {@link HeaderList} initialized with the specified headers. 1441 * 1442 * @param headers The headers to add to the list. Can be <jk>null</jk>. <jk>null</jk> entries are ignored. 1443 * @return A new unmodifiable instance, never <jk>null</jk>. 1444 */ 1445 public static final HeaderList headerList(List<Header> headers) { 1446 return HeaderList.of(headers); 1447 } 1448 1449 /** 1450 * Creates a new {@link HeaderList} initialized with the specified name/value pairs. 1451 * 1452 * @param pairs 1453 * Initial list of pairs. 1454 * <br>Must be an even number of parameters representing key/value pairs. 1455 * @throws RuntimeException If odd number of parameters were specified. 1456 * @return A new instance. 1457 */ 1458 public static HeaderList headerList(String...pairs) { 1459 return HeaderList.ofPairs(pairs); 1460 } 1461 1462 /** 1463 * Creates a new {@link Host} header. 1464 * 1465 * @param value 1466 * The header value. 1467 * <br>Can be <jk>null</jk>. 1468 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1469 */ 1470 public static final Host host(String value) { 1471 return Host.of(value); 1472 } 1473 1474 /** 1475 * Creates a new {@link Host} header with a delayed value. 1476 * 1477 * <p> 1478 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1479 * 1480 * @param value 1481 * The supplier of the header value. 1482 * <br>Can be <jk>null</jk>. 1483 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1484 */ 1485 public static final Host host(Supplier<String> value) { 1486 return Host.of(value); 1487 } 1488 1489 /** 1490 * Creates a new {@link IfMatch} header. 1491 * 1492 * @param value 1493 * The header value. 1494 * <br>Can be <jk>null</jk>. 1495 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1496 */ 1497 public static final IfMatch ifMatch(EntityTags value) { 1498 return IfMatch.of(value); 1499 } 1500 1501 /** 1502 * Creates a new {@link IfMatch} header. 1503 * 1504 * @param value 1505 * The header value. 1506 * <br>Must be a comma-delimited list of entity validator values (e.g. <js>"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""</js>). 1507 * <br>Can be <jk>null</jk>. 1508 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1509 */ 1510 public static final IfMatch ifMatch(String value) { 1511 return IfMatch.of(value); 1512 } 1513 1514 /** 1515 * Creates a new {@link IfMatch} header with a delayed value. 1516 * 1517 * <p> 1518 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1519 * 1520 * @param value 1521 * The supplier of the header value. 1522 * <br>Can be <jk>null</jk>. 1523 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1524 */ 1525 public static final IfMatch ifMatch(Supplier<EntityTags> value) { 1526 return IfMatch.of(value); 1527 } 1528 1529 /** 1530 * Creates a new {@link IfModifiedSince} header. 1531 * 1532 * @param value 1533 * The header value. 1534 * <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 1535 * <br>Can be <jk>null</jk>. 1536 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1537 */ 1538 public static final IfModifiedSince ifModifiedSince(String value) { 1539 return IfModifiedSince.of(value); 1540 } 1541 1542 /** 1543 * Creates a new {@link IfModifiedSince} header with a delayed value. 1544 * 1545 * <p> 1546 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1547 * 1548 * @param value 1549 * The supplier of the header value. 1550 * <br>Can be <jk>null</jk>. 1551 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1552 */ 1553 public static final IfModifiedSince ifModifiedSince(Supplier<ZonedDateTime> value) { 1554 return IfModifiedSince.of(value); 1555 } 1556 1557 /** 1558 * Creates a new {@link IfModifiedSince} header. 1559 * 1560 * @param value 1561 * The header value. 1562 * <br>Can be <jk>null</jk>. 1563 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1564 */ 1565 public static final IfModifiedSince ifModifiedSince(ZonedDateTime value) { 1566 return IfModifiedSince.of(value); 1567 } 1568 1569 /** 1570 * Creates a new {@link IfNoneMatch} header. 1571 * 1572 * @param value 1573 * The header value. 1574 * <br>Can be <jk>null</jk>. 1575 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1576 */ 1577 public static final IfNoneMatch ifNoneMatch(EntityTags value) { 1578 return IfNoneMatch.of(value); 1579 } 1580 1581 /** 1582 * Creates a new {@link IfNoneMatch} header. 1583 * 1584 * @param value 1585 * The header value. 1586 * <br>Must be a comma-delimited list of entity validator values (e.g. <js>"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""</js>). 1587 * <br>Can be <jk>null</jk>. 1588 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1589 */ 1590 public static final IfNoneMatch ifNoneMatch(String value) { 1591 return IfNoneMatch.of(value); 1592 } 1593 1594 /** 1595 * Creates a new {@link IfNoneMatch} header with a delayed value. 1596 * 1597 * <p> 1598 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1599 * 1600 * @param value 1601 * The supplier of the header value. 1602 * <br>Can be <jk>null</jk>. 1603 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1604 */ 1605 public static final IfNoneMatch ifNoneMatch(Supplier<EntityTags> value) { 1606 return IfNoneMatch.of(value); 1607 } 1608 1609 /** 1610 * Creates a new {@link IfRange} header. 1611 * 1612 * @param value 1613 * The header value. 1614 * <br>Can be <jk>null</jk>. 1615 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1616 */ 1617 public static final IfRange ifRange(EntityTag value) { 1618 return IfRange.of(value); 1619 } 1620 1621 /** 1622 * Creates a new {@link IfRange} header. 1623 * 1624 * @param value 1625 * The header value. 1626 * <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 1627 * <br>Can be <jk>null</jk>. 1628 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1629 */ 1630 public static final IfRange ifRange(String value) { 1631 return IfRange.of(value); 1632 } 1633 1634 /** 1635 * Creates a new {@link IfRange} header with a delayed value. 1636 * 1637 * <p> 1638 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1639 * 1640 * @param value 1641 * The supplier of the header value. 1642 * <br>Supplier must supply either {@link EntityTag} or {@link ZonedDateTime} objects. 1643 * <br>Can be <jk>null</jk>. 1644 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1645 */ 1646 public static final IfRange ifRange(Supplier<?> value) { 1647 return IfRange.of(value); 1648 } 1649 1650 /** 1651 * Creates a new {@link IfRange} header. 1652 * 1653 * @param value 1654 * The header value. 1655 * <br>Can be <jk>null</jk>. 1656 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1657 */ 1658 public static final IfRange ifRange(ZonedDateTime value) { 1659 return IfRange.of(value); 1660 } 1661 1662 /** 1663 * Creates a new {@link IfUnmodifiedSince} header. 1664 * 1665 * @param value 1666 * The header value. 1667 * <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 1668 * <br>Can be <jk>null</jk>. 1669 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1670 */ 1671 public static final IfUnmodifiedSince ifUnmodifiedSince(String value) { 1672 return IfUnmodifiedSince.of(value); 1673 } 1674 1675 /** 1676 * Creates a new {@link IfUnmodifiedSince} header with a delayed value. 1677 * 1678 * <p> 1679 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1680 * 1681 * @param value 1682 * The supplier of the header value. 1683 * <br>Can be <jk>null</jk>. 1684 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1685 */ 1686 public static final IfUnmodifiedSince ifUnmodifiedSince(Supplier<ZonedDateTime> value) { 1687 return IfUnmodifiedSince.of(value); 1688 } 1689 1690 /** 1691 * Creates a new {@link IfUnmodifiedSince} header. 1692 * 1693 * @param value 1694 * The header value. 1695 * <br>Can be <jk>null</jk>. 1696 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1697 */ 1698 public static final IfUnmodifiedSince ifUnmodifiedSince(ZonedDateTime value) { 1699 return IfUnmodifiedSince.of(value); 1700 } 1701 1702 /** 1703 * Creates a new {@link BasicIntegerHeader} header. 1704 * 1705 * @param name The header name. 1706 * @param value 1707 * The header value. 1708 * <br>Can be <jk>null</jk>. 1709 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1710 */ 1711 public static final BasicIntegerHeader integerHeader(String name, Integer value) { 1712 return BasicIntegerHeader.of(name, value); 1713 } 1714 1715 /** 1716 * Creates a new {@link BasicIntegerHeader} header. 1717 * 1718 * @param name The header name. 1719 * @param value 1720 * The header value. 1721 * <br>Must be parsable using {@link Integer#parseInt(String)}. 1722 * <br>Can be <jk>null</jk>. 1723 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1724 */ 1725 public static final BasicIntegerHeader integerHeader(String name, String value) { 1726 return BasicIntegerHeader.of(name, value); 1727 } 1728 1729 /** 1730 * Creates a new {@link BasicIntegerHeader} header with a delayed value. 1731 * 1732 * <p> 1733 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1734 * 1735 * @param name The header name. 1736 * @param value 1737 * The supplier of the header value. 1738 * <br>Can be <jk>null</jk>. 1739 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1740 */ 1741 public static final BasicIntegerHeader integerHeader(String name, Supplier<Integer> value) { 1742 return BasicIntegerHeader.of(name, value); 1743 } 1744 1745 /** 1746 * Creates a new {@link LastModified} header. 1747 * 1748 * @param value 1749 * The header value. 1750 * <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>). 1751 * <br>Can be <jk>null</jk>. 1752 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1753 */ 1754 public static final LastModified lastModified(String value) { 1755 return LastModified.of(value); 1756 } 1757 1758 /** 1759 * Creates a new {@link LastModified} header with a delayed value. 1760 * 1761 * <p> 1762 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1763 * 1764 * @param value 1765 * The supplier of the header value. 1766 * <br>Can be <jk>null</jk>. 1767 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1768 */ 1769 public static final LastModified lastModified(Supplier<ZonedDateTime> value) { 1770 return LastModified.of(value); 1771 } 1772 1773 /** 1774 * Creates a new {@link LastModified} header. 1775 * 1776 * @param value 1777 * The header value. 1778 * <br>Can be <jk>null</jk>. 1779 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1780 */ 1781 public static final LastModified lastModified(ZonedDateTime value) { 1782 return LastModified.of(value); 1783 } 1784 1785 /** 1786 * Creates a new {@link Location} header. 1787 * 1788 * @param value 1789 * The header value. 1790 * <br>Must be parsable by {@link URI#create(String)}. 1791 * <br>Can be <jk>null</jk>. 1792 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1793 */ 1794 public static final Location location(String value) { 1795 return Location.of(value); 1796 } 1797 1798 /** 1799 * Creates a new {@link Location} header with a delayed value. 1800 * 1801 * <p> 1802 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1803 * 1804 * @param value 1805 * The supplier of the header value. 1806 * <br>Can be <jk>null</jk>. 1807 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1808 */ 1809 public static final Location location(Supplier<URI> value) { 1810 return Location.of(value); 1811 } 1812 1813 /** 1814 * Creates a new {@link Location} header. 1815 * 1816 * @param value 1817 * The header value. 1818 * <br>Can be <jk>null</jk>. 1819 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1820 */ 1821 public static final Location location(URI value) { 1822 return Location.of(value); 1823 } 1824 1825 /** 1826 * Creates a new {@link BasicLongHeader} header. 1827 * 1828 * @param name The header name. 1829 * @param value 1830 * The header value. 1831 * <br>Must be parsable by {@link Long#parseLong(String)}. 1832 * <br>Can be <jk>null</jk>. 1833 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1834 */ 1835 public static final BasicLongHeader longHeader(String name, Long value) { 1836 return BasicLongHeader.of(name, value); 1837 } 1838 1839 /** 1840 * Creates a new {@link BasicLongHeader} header. 1841 * 1842 * @param name The header name. 1843 * @param value 1844 * The header value. 1845 * <br>Must be parsable by {@link Long#parseLong(String)}. 1846 * <br>Can be <jk>null</jk>. 1847 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1848 */ 1849 public static final BasicLongHeader longHeader(String name, String value) { 1850 return BasicLongHeader.of(name, value); 1851 } 1852 1853 /** 1854 * Creates a new {@link BasicLongHeader} header with a delayed value. 1855 * 1856 * <p> 1857 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1858 * 1859 * @param name The header name. 1860 * @param value 1861 * The supplier of the header value. 1862 * <br>Can be <jk>null</jk>. 1863 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1864 */ 1865 public static final BasicLongHeader longHeader(String name, Supplier<Long> value) { 1866 return BasicLongHeader.of(name, value); 1867 } 1868 1869 /** 1870 * Creates a new {@link MaxForwards} header. 1871 * 1872 * @param value 1873 * The header value. 1874 * <br>Can be <jk>null</jk>. 1875 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1876 */ 1877 public static final MaxForwards maxForwards(Integer value) { 1878 return MaxForwards.of(value); 1879 } 1880 1881 /** 1882 * Creates a new {@link MaxForwards} header. 1883 * 1884 * @param value 1885 * The header value. 1886 * <br>Must be parsable using {@link Integer#parseInt(String)}. 1887 * <br>Can be <jk>null</jk>. 1888 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1889 */ 1890 public static final MaxForwards maxForwards(String value) { 1891 return MaxForwards.of(value); 1892 } 1893 1894 /** 1895 * Creates a new {@link MaxForwards} header with a delayed value. 1896 * 1897 * <p> 1898 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1899 * 1900 * @param value 1901 * The supplier of the header value. 1902 * <br>Can be <jk>null</jk>. 1903 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 1904 */ 1905 public static final MaxForwards maxForwards(Supplier<Integer> value) { 1906 return MaxForwards.of(value); 1907 } 1908 1909 /** 1910 * Creates a new {@link BasicMediaRangesHeader} header. 1911 * 1912 * @param name The header name. 1913 * @param value 1914 * The header value. 1915 * <br>Can be <jk>null</jk>. 1916 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1917 */ 1918 public static final BasicMediaRangesHeader mediaRangesHeader(String name, MediaRanges value) { 1919 return BasicMediaRangesHeader.of(name, value); 1920 } 1921 1922 /** 1923 * Creates a new {@link BasicMediaRangesHeader} header. 1924 * 1925 * @param name The header name. 1926 * @param value 1927 * The header value. 1928 * <br>Must be parsable by {@link MediaRanges#of(String)}. 1929 * <br>Can be <jk>null</jk>. 1930 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1931 */ 1932 public static final BasicMediaRangesHeader mediaRangesHeader(String name, String value) { 1933 return BasicMediaRangesHeader.of(name, value); 1934 } 1935 1936 /** 1937 * Creates a new {@link BasicMediaRangesHeader} header with a delayed value. 1938 * 1939 * <p> 1940 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1941 * 1942 * @param name The header name. 1943 * @param value 1944 * The header value. 1945 * <br>Must be parsable by {@link MediaRanges#of(String)}. 1946 * <br>Can be <jk>null</jk>. 1947 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1948 */ 1949 public static final BasicMediaRangesHeader mediaRangesHeader(String name, Supplier<MediaRanges> value) { 1950 return value == null ? null : new BasicMediaRangesHeader(name, value); 1951 } 1952 1953 /** 1954 * Creates a new {@link BasicMediaTypeHeader} header. 1955 * 1956 * @param name The header name. 1957 * @param value 1958 * The header value. 1959 * <br>Can be <jk>null</jk>. 1960 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1961 */ 1962 public static final BasicMediaTypeHeader mediaTypeHeader(String name, MediaType value) { 1963 return BasicMediaTypeHeader.of(name, value); 1964 } 1965 1966 /** 1967 * Creates a new {@link BasicMediaTypeHeader} header. 1968 * 1969 * @param name The header name. 1970 * @param value 1971 * The header value. 1972 * <br>Must be parsable by {@link MediaType#of(String)}. 1973 * <br>Can be <jk>null</jk>. 1974 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1975 */ 1976 public static final BasicMediaTypeHeader mediaTypeHeader(String name, String value) { 1977 return BasicMediaTypeHeader.of(name, value); 1978 } 1979 1980 /** 1981 * Creates a new {@link BasicMediaTypeHeader} header with a delayed value. 1982 * 1983 * <p> 1984 * Header value is re-evaluated on each call to {@link Header#getValue()}. 1985 * 1986 * @param name The header name. 1987 * @param value 1988 * The header value. 1989 * <br>Can be <jk>null</jk>. 1990 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 1991 */ 1992 public static final BasicMediaTypeHeader mediaTypeHeader(String name, Supplier<MediaType> value) { 1993 return value == null ? null : new BasicMediaTypeHeader(name, value); 1994 } 1995 1996 /** 1997 * Creates a new {@link NoTrace} header. 1998 * 1999 * @param value 2000 * The header value. 2001 * <br>Can be <jk>null</jk>. 2002 * @return A new header bean, or <jk>null</jk> if the value was <jk>null</jk>. 2003 */ 2004 public static final NoTrace noTrace(Boolean value) { 2005 return NoTrace.of(value); 2006 } 2007 2008 /** 2009 * Creates a new {@link NoTrace} header. 2010 * 2011 * @param value 2012 * The header value. 2013 * <br>Must be parsable by {@link Boolean#parseBoolean(String)}. 2014 * <br>Can be <jk>null</jk>. 2015 * @return A new header bean, or <jk>null</jk> if the value was <jk>null</jk>. 2016 */ 2017 public static final NoTrace noTrace(String value) { 2018 return NoTrace.of(value); 2019 } 2020 2021 /** 2022 * Creates a new {@link NoTrace} header with a delayed value. 2023 * 2024 * <p> 2025 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2026 * 2027 * @param value 2028 * The header value supplier. 2029 * <br>Can be <jk>null</jk>. 2030 * @return A new header bean, or <jk>null</jk> if the value was <jk>null</jk>. 2031 */ 2032 public static final NoTrace noTrace(Supplier<Boolean> value) { 2033 return NoTrace.of(value); 2034 } 2035 2036 /** 2037 * Creates a new {@link Origin} header. 2038 * 2039 * @param value 2040 * The header value. 2041 * <br>Can be <jk>null</jk>. 2042 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2043 */ 2044 public static final Origin origin(String value) { 2045 return Origin.of(value); 2046 } 2047 2048 /** 2049 * Creates a new {@link Origin} header with a delayed value. 2050 * 2051 * <p> 2052 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2053 * 2054 * @param value 2055 * The supplier of the header value. 2056 * <br>Can be <jk>null</jk>. 2057 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2058 */ 2059 public static final Origin origin(Supplier<String> value) { 2060 return Origin.of(value); 2061 } 2062 2063 /** 2064 * Creates a new {@link Pragma} header. 2065 * 2066 * @param value 2067 * The header value. 2068 * <br>Can be <jk>null</jk>. 2069 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2070 */ 2071 public static final Pragma pragma(String value) { 2072 return Pragma.of(value); 2073 } 2074 2075 /** 2076 * Creates a new {@link Pragma} header with a delayed value. 2077 * 2078 * <p> 2079 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2080 * 2081 * @param value 2082 * The header value. 2083 * <br>Can be <jk>null</jk>. 2084 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2085 */ 2086 public static final Pragma pragma(Supplier<String> value) { 2087 return Pragma.of(value); 2088 } 2089 2090 /** 2091 * Creates a new {@link ProxyAuthenticate} header. 2092 * 2093 * @param value 2094 * The header value. 2095 * <br>Can be <jk>null</jk>. 2096 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2097 */ 2098 public static final ProxyAuthenticate proxyAuthenticate(String value) { 2099 return ProxyAuthenticate.of(value); 2100 } 2101 2102 /** 2103 * Creates a new {@link ProxyAuthenticate} header with a delayed value. 2104 * 2105 * <p> 2106 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2107 * 2108 * @param value 2109 * The supplier of the header value. 2110 * <br>Can be <jk>null</jk>. 2111 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2112 */ 2113 public static final ProxyAuthenticate proxyAuthenticate(Supplier<String> value) { 2114 return ProxyAuthenticate.of(value); 2115 } 2116 2117 /** 2118 * Creates a new {@link ProxyAuthorization} header. 2119 * 2120 * @param value 2121 * The header value. 2122 * <br>Can be <jk>null</jk>. 2123 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2124 */ 2125 public static final ProxyAuthorization proxyAuthorization(String value) { 2126 return ProxyAuthorization.of(value); 2127 } 2128 2129 /** 2130 * Creates a new {@link ProxyAuthorization} header with a delayed value. 2131 * 2132 * <p> 2133 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2134 * 2135 * @param value 2136 * The supplier of the header value. 2137 * <br>Can be <jk>null</jk>. 2138 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2139 */ 2140 public static final ProxyAuthorization proxyAuthorization(Supplier<String> value) { 2141 return ProxyAuthorization.of(value); 2142 } 2143 2144 /** 2145 * Creates a new {@link Range} header. 2146 * 2147 * @param value 2148 * The header value. 2149 * <br>Can be <jk>null</jk>. 2150 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2151 */ 2152 public static final Range range(String value) { 2153 return Range.of(value); 2154 } 2155 2156 /** 2157 * Creates a new {@link Range} header with a delayed value. 2158 * 2159 * <p> 2160 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2161 * 2162 * @param value 2163 * The supplier of the header value. 2164 * <br>Can be <jk>null</jk>. 2165 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2166 */ 2167 public static final Range range(Supplier<String> value) { 2168 return Range.of(value); 2169 } 2170 2171 /** 2172 * Creates a new {@link Referer} header. 2173 * 2174 * @param value 2175 * The header value. 2176 * <br>Must be parsable by {@link URI#create(String)}. 2177 * <br>Can be <jk>null</jk>. 2178 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2179 */ 2180 public static final Referer referer(String value) { 2181 return Referer.of(value); 2182 } 2183 2184 /** 2185 * Creates a new {@link Referer} header with a delayed value. 2186 * 2187 * <p> 2188 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2189 * 2190 * @param value 2191 * The supplier of the header value. 2192 * <br>Can be <jk>null</jk>. 2193 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2194 */ 2195 public static final Referer referer(Supplier<URI> value) { 2196 return Referer.of(value); 2197 } 2198 2199 /** 2200 * Creates a new {@link Referer} header. 2201 * 2202 * @param value 2203 * The header value. 2204 * <br>Must be parsable by {@link URI#create(String)}. 2205 * <br>Can be <jk>null</jk>. 2206 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2207 */ 2208 public static final Referer referer(URI value) { 2209 return Referer.of(value); 2210 } 2211 2212 /** 2213 * Creates a new {@link RetryAfter} header. 2214 * 2215 * @param value 2216 * The header value. 2217 * <br>Can be <jk>null</jk>. 2218 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2219 */ 2220 public static final RetryAfter retryAfter(Integer value) { 2221 return RetryAfter.of(value); 2222 } 2223 2224 /** 2225 * Creates a new {@link RetryAfter} header. 2226 * 2227 * @param value 2228 * The header value. 2229 * <br>Must be an RFC-1123 formated string (e.g. <js>"Sat, 29 Oct 1994 19:43:31 GMT"</js>) or an integer. 2230 * <br>Can be <jk>null</jk>. 2231 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2232 */ 2233 public static final RetryAfter retryAfter(String value) { 2234 return RetryAfter.of(value); 2235 } 2236 2237 /** 2238 * Creates a new {@link RetryAfter} header with a delayed value. 2239 * 2240 * <p> 2241 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2242 * 2243 * @param value 2244 * The supplier of the header value. 2245 * <br>Supplier must supply either {@link Integer} or {@link ZonedDateTime} objects. 2246 * <br>Can be <jk>null</jk>. 2247 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2248 */ 2249 public static final RetryAfter retryAfter(Supplier<?> value) { 2250 return RetryAfter.of(value); 2251 } 2252 2253 /** 2254 * Creates a new {@link RetryAfter} header. 2255 * 2256 * @param value 2257 * The header value. 2258 * <br>Can be <jk>null</jk>. 2259 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2260 */ 2261 public static final RetryAfter retryAfter(ZonedDateTime value) { 2262 return RetryAfter.of(value); 2263 } 2264 2265 /** 2266 * Creates a new {@link SerializedHeader} header. 2267 * 2268 * @param name The header name. 2269 * @param value 2270 * The POJO to serialize as the header value. 2271 * <br>Can be <jk>null</jk>. 2272 * @return A new header bean. Never <jk>null</jk>. 2273 * @throws IllegalArgumentException If name is <jk>null</jk> or empty. 2274 */ 2275 public static final SerializedHeader serializedHeader(String name, Object value) { 2276 return SerializedHeader.of(name, value); 2277 } 2278 2279 /** 2280 * Creates a new {@link SerializedHeader} header. 2281 * 2282 * @param name The HTTP header name name. 2283 * @param value 2284 * The POJO to serialize as the header value. 2285 * @param serializer 2286 * The serializer to use for serializing the value to a string value. 2287 * @param schema 2288 * The schema object that defines the format of the output. 2289 * <br>If <jk>null</jk>, defaults to the schema defined on the serializer. 2290 * <br>If that's also <jk>null</jk>, defaults to {@link HttpPartSchema#DEFAULT}. 2291 * <br>Only used if serializer is schema-aware (e.g. {@link OpenApiSerializer}). 2292 * <br>Can also be a {@link Supplier}. 2293 * @param skipIfEmpty If value is a blank string, the value should return as <jk>null</jk>. 2294 * @return A new header bean. Never <jk>null</jk>. 2295 * @throws IllegalArgumentException If name is <jk>null</jk> or empty. 2296 */ 2297 public static SerializedHeader serializedHeader(String name, Object value, HttpPartSerializerSession serializer, HttpPartSchema schema, boolean skipIfEmpty) { 2298 return SerializedHeader.of(name, value, serializer, schema, skipIfEmpty); 2299 } 2300 2301 /** 2302 * Creates a new {@link SerializedHeader} header with a delayed value. 2303 * 2304 * <p> 2305 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2306 * 2307 * @param name The header name. 2308 * @param value 2309 * The supplier of the POJO to serialize as the header value. 2310 * <br>Can be <jk>null</jk>. 2311 * @return A new header bean. Never <jk>null</jk>. 2312 * @throws IllegalArgumentException If name is <jk>null</jk> or empty. 2313 */ 2314 public static final SerializedHeader serializedHeader(String name, Supplier<?> value) { 2315 return SerializedHeader.of(name, value); 2316 } 2317 2318 /** 2319 * Creates a new {@link SerializedHeader} header. 2320 * 2321 * <p> 2322 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2323 * 2324 * @param name The HTTP header name name. 2325 * @param value 2326 * The supplier of the POJO to serialize as the header value. 2327 * @param serializer 2328 * The serializer to use for serializing the value to a string value. 2329 * @param schema 2330 * The schema object that defines the format of the output. 2331 * <br>If <jk>null</jk>, defaults to the schema defined on the serializer. 2332 * <br>If that's also <jk>null</jk>, defaults to {@link HttpPartSchema#DEFAULT}. 2333 * <br>Only used if serializer is schema-aware (e.g. {@link OpenApiSerializer}). 2334 * <br>Can also be a {@link Supplier}. 2335 * @param skipIfEmpty If value is a blank string, the value should return as <jk>null</jk>. 2336 * @return A new header bean. Never <jk>null</jk>. 2337 * @throws IllegalArgumentException If name is <jk>null</jk> or empty. 2338 */ 2339 public static SerializedHeader serializedHeader(String name, Supplier<?> value, HttpPartSerializerSession serializer, HttpPartSchema schema, boolean skipIfEmpty) { 2340 return SerializedHeader.of(name, value, serializer, schema, skipIfEmpty); 2341 } 2342 2343 /** 2344 * Creates a new {@link Server} header. 2345 * 2346 * @param value 2347 * The header value. 2348 * <br>Can be <jk>null</jk>. 2349 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2350 */ 2351 public static final Server server(String value) { 2352 return Server.of(value); 2353 } 2354 2355 /** 2356 * Creates a new {@link Server} header with a delayed value. 2357 * 2358 * <p> 2359 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2360 * 2361 * @param value 2362 * The supplier of the header value. 2363 * <br>Can be <jk>null</jk>. 2364 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2365 */ 2366 public static final Server server(Supplier<String> value) { 2367 return Server.of(value); 2368 } 2369 2370 /** 2371 * Creates a {@link BasicHeader} from a name/value pair string (e.g. <js>"Foo: bar"</js>) 2372 * 2373 * @param pair The pair string. 2374 * @return A new header bean, or <jk>null</jk> if the value was <jk>null</jk>. 2375 */ 2376 public static final BasicStringHeader stringHeader(String pair) { 2377 return BasicStringHeader.ofPair(pair); 2378 } 2379 2380 /** 2381 * Creates a new {@link BasicStringHeader} header. 2382 * 2383 * @param name The header name. 2384 * @param value 2385 * The header value. 2386 * <br>Can be <jk>null</jk>. 2387 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2388 */ 2389 public static final BasicStringHeader stringHeader(String name, String value) { 2390 return BasicStringHeader.of(name, value); 2391 } 2392 2393 /** 2394 * Creates a new {@link BasicStringHeader} header with a delayed value. 2395 * 2396 * <p> 2397 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2398 * 2399 * @param name The header name. 2400 * @param value 2401 * The supplier of the header value. 2402 * <br>Can be <jk>null</jk>. 2403 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2404 */ 2405 public static final BasicStringHeader stringHeader(String name, Supplier<String> value) { 2406 return BasicStringHeader.of(name, value); 2407 } 2408 2409 /** 2410 * Creates a new {@link BasicStringRangesHeader} header. 2411 * 2412 * @param name The header name. 2413 * @param value 2414 * The header value. 2415 * <br>Must be parsable by {@link StringRanges#of(String)}. 2416 * <br>Can be <jk>null</jk>. 2417 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2418 */ 2419 public static final BasicStringRangesHeader stringRangesHeader(String name, String value) { 2420 return BasicStringRangesHeader.of(name, value); 2421 } 2422 2423 /** 2424 * Creates a new {@link BasicStringRangesHeader} header. 2425 * 2426 * @param name The header name. 2427 * @param value 2428 * The header value. 2429 * <br>Can be <jk>null</jk>. 2430 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2431 */ 2432 public static final BasicStringRangesHeader stringRangesHeader(String name, StringRanges value) { 2433 return BasicStringRangesHeader.of(name, value); 2434 } 2435 2436 /** 2437 * Creates a new {@link BasicStringRangesHeader} header with a delayed value. 2438 * 2439 * <p> 2440 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2441 * 2442 * @param name The header name. 2443 * @param value 2444 * The supplier of the header value. 2445 * <br>Can be <jk>null</jk>. 2446 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2447 */ 2448 public static final BasicStringRangesHeader stringRangesHeader(String name, Supplier<StringRanges> value) { 2449 return BasicStringRangesHeader.of(name, value); 2450 } 2451 2452 /** 2453 * Creates a new {@link TE} header. 2454 * 2455 * @param value 2456 * The header value. 2457 * <br>Must be parsable by {@link StringRanges#of(String)}. 2458 * <br>Can be <jk>null</jk>. 2459 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2460 */ 2461 public static final TE te(String value) { 2462 return TE.of(value); 2463 } 2464 2465 /** 2466 * Creates a new {@link TE} header. 2467 * 2468 * @param value 2469 * The header value. 2470 * <br>Can be <jk>null</jk>. 2471 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2472 */ 2473 public static final TE te(StringRanges value) { 2474 return TE.of(value); 2475 } 2476 2477 /** 2478 * Creates a new {@link TE} header with a delayed value. 2479 * 2480 * <p> 2481 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2482 * 2483 * @param value 2484 * The supplier of the header value. 2485 * <br>Can be <jk>null</jk>. 2486 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2487 */ 2488 public static final TE te(Supplier<StringRanges> value) { 2489 return TE.of(value); 2490 } 2491 2492 /** 2493 * Creates a new {@link Thrown} header. 2494 * 2495 * @param value 2496 * The header value. 2497 * <br>Can be <jk>null</jk>. 2498 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2499 */ 2500 public static final Thrown thrown(String value) { 2501 return Thrown.of(value); 2502 } 2503 2504 /** 2505 * Creates a new {@link Thrown} header. 2506 * 2507 * @param value 2508 * The header value. 2509 * <br>Can be <jk>null</jk>. 2510 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2511 */ 2512 public static final Thrown thrown(Throwable...value) { 2513 return Thrown.of(value); 2514 } 2515 2516 /** 2517 * Creates a new {@link Trailer} header. 2518 * 2519 * @param value 2520 * The header value. 2521 * <br>Can be <jk>null</jk>. 2522 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2523 */ 2524 public static final Trailer trailer(String value) { 2525 return Trailer.of(value); 2526 } 2527 2528 /** 2529 * Creates a new {@link Trailer} header with a delayed value. 2530 * 2531 * <p> 2532 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2533 * 2534 * @param value 2535 * The supplier of the header value. 2536 * <br>Can be <jk>null</jk>. 2537 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2538 */ 2539 public static final Trailer trailer(Supplier<String> value) { 2540 return Trailer.of(value); 2541 } 2542 2543 /** 2544 * Creates a new {@link TransferEncoding} header. 2545 * 2546 * @param value 2547 * The header value. 2548 * <br>Can be <jk>null</jk>. 2549 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2550 */ 2551 public static final TransferEncoding transferEncoding(String value) { 2552 return TransferEncoding.of(value); 2553 } 2554 2555 /** 2556 * Creates a new {@link TransferEncoding} header with a delayed value. 2557 * 2558 * <p> 2559 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2560 * 2561 * @param value 2562 * The supplier of the header value. 2563 * <br>Can be <jk>null</jk>. 2564 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2565 */ 2566 public static final TransferEncoding transferEncoding(Supplier<String> value) { 2567 return TransferEncoding.of(value); 2568 } 2569 2570 /** 2571 * Creates a new {@link Upgrade} header. 2572 * 2573 * @param value 2574 * The header value. 2575 * <br>Can be <jk>null</jk>. 2576 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2577 */ 2578 public static final Upgrade upgrade(String value) { 2579 return Upgrade.of(value); 2580 } 2581 2582 /** 2583 * Creates a new {@link Upgrade} header. 2584 * 2585 * @param value 2586 * The header value. 2587 * <br>Can be <jk>null</jk>. 2588 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2589 */ 2590 public static final Upgrade upgrade(String...value) { 2591 return Upgrade.of(value); 2592 } 2593 2594 /** 2595 * Creates a new {@link Upgrade} header with a delayed value. 2596 * 2597 * <p> 2598 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2599 * 2600 * @param value 2601 * The supplier of the header value. 2602 * <br>Can be <jk>null</jk>. 2603 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2604 */ 2605 public static final Upgrade upgrade(Supplier<String[]> value) { 2606 return Upgrade.of(value); 2607 } 2608 2609 /** 2610 * Creates a new {@link BasicUriHeader} header. 2611 * 2612 * @param name The header name. 2613 * @param value 2614 * The header value. 2615 * <br>Must be parsable by {@link URI#create(String)}. 2616 * <br>Can be <jk>null</jk>. 2617 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2618 */ 2619 public static final BasicUriHeader uriHeader(String name, String value) { 2620 return BasicUriHeader.of(name, value); 2621 } 2622 2623 /** 2624 * Creates a new {@link BasicUriHeader} header with a delayed value. 2625 * 2626 * <p> 2627 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2628 * 2629 * @param name The header name. 2630 * @param value 2631 * The supplier of the header value. 2632 * <br>Can be <jk>null</jk>. 2633 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2634 */ 2635 public static final BasicUriHeader uriHeader(String name, Supplier<URI> value) { 2636 return BasicUriHeader.of(name, value); 2637 } 2638 2639 /** 2640 * Creates a new {@link BasicUriHeader} header. 2641 * 2642 * @param name The header name. 2643 * @param value 2644 * The header value. 2645 * <br>Can be <jk>null</jk>. 2646 * @return A new header bean, or <jk>null</jk> if the name is <jk>null</jk> or empty or the value is <jk>null</jk>. 2647 */ 2648 public static final BasicUriHeader uriHeader(String name, URI value) { 2649 return BasicUriHeader.of(name, value); 2650 } 2651 2652 /** 2653 * Creates a new {@link UserAgent} header. 2654 * 2655 * @param value 2656 * The header value. 2657 * <br>Can be <jk>null</jk>. 2658 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2659 */ 2660 public static final UserAgent userAgent(String value) { 2661 return UserAgent.of(value); 2662 } 2663 2664 /** 2665 * Creates a new {@link UserAgent} header with a delayed value. 2666 * 2667 * <p> 2668 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2669 * 2670 * @param value 2671 * The supplier of the header value. 2672 * <br>Can be <jk>null</jk>. 2673 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2674 */ 2675 public static final UserAgent userAgent(Supplier<String> value) { 2676 return UserAgent.of(value); 2677 } 2678 2679 /** 2680 * Creates a new {@link Vary} header. 2681 * 2682 * @param value 2683 * The header value. 2684 * <br>Can be <jk>null</jk>. 2685 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2686 */ 2687 public static final Vary vary(String value) { 2688 return Vary.of(value); 2689 } 2690 2691 /** 2692 * Creates a new {@link Vary} header with a delayed value. 2693 * 2694 * <p> 2695 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2696 * 2697 * @param value 2698 * The supplier of the header value. 2699 * <br>Can be <jk>null</jk>. 2700 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2701 */ 2702 public static final Vary vary(Supplier<String> value) { 2703 return Vary.of(value); 2704 } 2705 2706 /** 2707 * Creates a new {@link Via} header. 2708 * 2709 * @param value 2710 * The header value. 2711 * <br>Can be <jk>null</jk>. 2712 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2713 */ 2714 public static final Via via(String value) { 2715 return Via.of(value); 2716 } 2717 2718 /** 2719 * Creates a new {@link Via} header. 2720 * 2721 * @param value 2722 * The header value. 2723 * <br>Can be <jk>null</jk>. 2724 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2725 */ 2726 public static final Via via(String...value) { 2727 return Via.of(value); 2728 } 2729 2730 /** 2731 * Creates a new {@link Via} header with a delayed value. 2732 * 2733 * <p> 2734 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2735 * 2736 * @param value 2737 * The supplier of the header value. 2738 * <br>Can be <jk>null</jk>. 2739 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2740 */ 2741 public static final Via via(Supplier<String[]> value) { 2742 return Via.of(value); 2743 } 2744 2745 /** 2746 * Creates a new {@link Warning} header. 2747 * 2748 * @param value 2749 * The header value. 2750 * <br>Can be <jk>null</jk>. 2751 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2752 */ 2753 public static final Warning warning(String value) { 2754 return Warning.of(value); 2755 } 2756 2757 /** 2758 * Creates a new {@link Warning} header with a delayed value. 2759 * 2760 * <p> 2761 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2762 * 2763 * @param value 2764 * The supplier of the header value. 2765 * <br>Can be <jk>null</jk>. 2766 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2767 */ 2768 public static final Warning warning(Supplier<String> value) { 2769 return Warning.of(value); 2770 } 2771 2772 /** 2773 * Creates a new {@link WwwAuthenticate} header. 2774 * 2775 * @param value 2776 * The header value. 2777 * <br>Can be <jk>null</jk>. 2778 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2779 */ 2780 public static final WwwAuthenticate wwwAuthenticate(String value) { 2781 return WwwAuthenticate.of(value); 2782 } 2783 2784 /** 2785 * Creates a new {@link WwwAuthenticate} header with a delayed value. 2786 * 2787 * <p> 2788 * Header value is re-evaluated on each call to {@link Header#getValue()}. 2789 * 2790 * @param value 2791 * The supplier of the header value. 2792 * <br>Can be <jk>null</jk>. 2793 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 2794 */ 2795 public static final WwwAuthenticate wwwAuthenticate(Supplier<String> value) { 2796 return WwwAuthenticate.of(value); 2797 } 2798}