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