{title:'Response Headers', created:'8.2.0', updated:'9.0.0'}

Response headers are accessed through the following methods:

- {@link oajrc.RestResponse}
  - {@link oajrc.RestResponse#getHeader(String) getHeader(String)} returns {@link oajrc.ResponseHeader}
  - {@link oajrc.RestResponse#getHeaders(String) getHeaders(String)} returns {@link oajrc.ResponseHeader}[]
  - {@link oajrc.RestResponse#getFirstHeader(String) getFirstHeader(String)} returns {@link oajrc.ResponseHeader}
  - {@link oajrc.RestResponse#getLastHeader(String) getLastHeader(String)} returns {@link oajrc.ResponseHeader}
  - {@link oajrc.RestResponse#getAllHeaders() getAllHeaders()} returns {@link oajrc.ResponseHeader}[]
  - {@link oajrc.RestResponse#getStringHeader(String) getStringHeader(String)} returns String
  - {@link oajrc.RestResponse#containsHeader(String) containsHeader(String)} returns boolean

Unlike {@link oajrc.RestResponse#getFirstHeader(String)} and {@link oajrc.RestResponse#getLastHeader(String)}, the {@link oajrc.RestResponse#getHeader(String)} method returns an empty {@link oajrc.ResponseHeader} object instead of returning null. This allows it to be used more easily in fluent calls.

##### Example:

| RestResponse res = client.get(URI).complete(); | ResponseHeader header = res.getHeader("Location"); | | // See if response contains Location header. | boolean hasLocationHeader = header.isPresent(); | | // Get actual value if it exists. | String locationHeader1 = header.orElse("http://localhost"); | | // Converted to object. | URI locationHeader2 = header.as(URI.class).orElse(null);

The {@link oajrc.ResponseHeader} class extends from the HttpClient {@link org.apache.http.Header} class and provides several convenience methods:

- {@link oajrc.ResponseHeader}
  - {@link oajrc.ResponseHeader#isPresent() isPresent()} returns boolean
  - {@link oajrc.ResponseHeader#asString() asString()} returns String
  - {@link oajrc.ResponseHeader#as(Type,Type...) as(Type,Type...)} returns T
  - {@link oajrc.ResponseHeader#as(Class) as(Class<T>)} returns T
  - {@link oajrc.ResponseHeader#asMatcher(Pattern) asMatcher(Pattern)} returns {@link java.util.regex.Matcher}
  - {@link oajrc.ResponseHeader#asMatcher(String) asMatcher(String)} returns {@link java.util.regex.Matcher}
  - {@link oajrc.ResponseHeader#asHeader(Class) asHeader(Class<T extends BasicHeader> c)} returns {@link oaj.http.BasicHeader}
  - {@link oajrc.ResponseHeader#asStringHeader() asStringHeader()} returns {@link oaj.http.header.BasicIntegerHeader}
  - {@link oajrc.ResponseHeader#asIntegerHeader() asIntegerHeader()} returns {@link oaj.http.header.BasicStringHeader}
  - {@link oajrc.ResponseHeader#asLongHeader() asLongHeader()} returns {@link oaj.http.header.BasicLongHeader}
  - {@link oajrc.ResponseHeader#asDateHeader() asDateHeader()} returns {@link oaj.http.header.BasicDateHeader}
  - {@link oajrc.ResponseHeader#asCsvHeader() asCsvHeader()} returns {@link oaj.http.header.BasicCsvHeader}
  - {@link oajrc.ResponseHeader#asEntityTagsHeader() asEntityTagsHeader()} returns {@link oaj.http.header.BasicEntityTagsHeader}
  - {@link oajrc.ResponseHeader#asStringRangesHeader() asStringRangesHeader()} returns {@link oaj.http.header.BasicStringRangesHeader}
  - {@link oajrc.ResponseHeader#asUriHeader() asUriHeader()} returns {@link oaj.http.header.BasicUriHeader}

The {@link oajrc.ResponseHeader#schema(HttpPartSchema)} method allows you to perform parsing of OpenAPI formats for header parts.

##### Example:

| // Parse the header "Foo: bar|baz". | List<String> fooHeader = client | .get(URI) | .complete() | .getHeader("Foo").schema(T_ARRAY_PIPES).as(List.class, String.class);

Assertion methods are also provided for fluent-style calls:

- {@link oajrc.ResponseHeader}
  - {@link oajrc.ResponseHeader#assertString() assertString()} returns {@link oaj.assertions.FluentStringAssertion}
  - {@link oajrc.ResponseHeader#assertInteger() assertInteger()} returns {@link oaj.assertions.FluentIntegerAssertion}
  - {@link oajrc.ResponseHeader#assertLong() assertLong()} returns {@link oaj.assertions.FluentLongAssertion}
  - {@link oajrc.ResponseHeader#assertZonedDateTime() assertZonedDateTime()} returns {@link oaj.assertions.FluentZonedDateTimeAssertion}

Note how in the following example, the fluent assertion returns control to the {@link oajrc.RestResponse} object after the assertion has been completed:

##### Example:

| // Assert the response content type is any sort of JSON. | String content = client.get(URI) | .run() | .getHeader("Content-Type").assertString().matchesSimple("application/json*") | .getContent().asString();