Standard Header

Standard headers like Content-Type and Accept are set on your behalf. When payload content is present then values are based on the content type you are sending. When no payload is present, it defaults to application/json .

Explicit Header

To explicitly set header pass http.header(values) as an additional parameter. Groovy http.get("/end-point", http.header("Accept", "application/octet-stream")) { // assertions go here } http.get("/end-point", [queryParam1: "queryParamValue1"], http.header("Accept", "application/octet-stream")) { // assertions go here } http.patch("/end-point", http.header("Accept", "application/octet-stream"), [fileId: "myFile"]) { // assertions go here } http.post("/end-point", http.header("Accept", "application/octet-stream"), [fileId: "myFile"]) { // assertions go here } http.put("/end-point", http.header("Accept", "application/octet-stream"), [fileId: "myFile", file: sampleFile]) { // assertions go here } http.delete("/end-point", http.header("Custom-Header", "special-value")) Java http.get("/end-point", http.header("Accept", "application/octet-stream"), (header, body) -> { // assertions go here }); http.get("/end-point", http.query("queryParam1", "queryParamValue1"), http.header("Accept", "application/octet-stream"), (header, body) -> { // assertions go here }); http.patch("/end-point", http.header("Accept", "application/octet-stream"), http.json("fileId", "myFile"), (header, body) -> { // assertions go here }); http.post("/end-point", http.header("Accept", "application/octet-stream"), http.json("fileId", "myFile"), (header, body) -> { // assertions go here }); http.put("/end-point", http.header("Accept", "application/octet-stream"), http.json("fileId", "myFile", "file", sampleFile), (header, body) -> { // assertions go here }); http.delete("/end-point", http.header("Custom-Header", "special-value")); Additionally http.header accepts values as a map. Groovy def varArgHeader = http.header( "My-Header1", "Value1", "My-Header2", "Value2") def mapBasedHeader = http.header([ "My-Header1": "Value1", "My-Header2": "Value2"]) Java HttpHeader varArgHeader = http.header( "My-Header1", "Value1", "My-Header2", "Value2"); Map<CharSequence, CharSequence> headerValues = new HashMap<>(); headerValues.put("My-Header1", "Value1"); headerValues.put("My-Header2", "Value2"); HttpHeader mapBasedHeader = http.header(headerValues); Use .with to create a new instance of a header based on the existing one plus additional values Groovy def newHeaderVarArg = header.with( "Additional-1", "AdditionalValue1", "Additional-2", "AdditionalValue2") def newHeaderMap = header.with([ "Additional-1": "AdditionalValue1", "Additional-2": "AdditionalValue2"]) Java HttpHeader newHeaderVarArg = header.with( "Additional-1", "AdditionalValue1", "Additional-2", "AdditionalValue2"); Map<CharSequence, CharSequence> additionalValues = new HashMap<>(); additionalValues.put("Additional-1", "AdditionalValue1"); additionalValues.put("Additional-2", "AdditionalValue2"); HttpHeader newHeaderMap = header.with(additionalValues);

Implicit Header

Webtau has a way to provide headers for each call implicitly. Use it to provide things like authentication, version, etc. header values.Implicit headers goal is to reduce expose to implementation details and make tests more robust. Groovy package scenarios.rest.headers import scenarios.rest.headers.auth.Auth url = "http://localhost:8080" httpHeaderProvider = Auth.&authHeader Where Auth.&authHeader is implemented as follows: package scenarios.rest.headers.auth import org.testingisdocumenting.webtau.http.HttpHeader class Auth { static HttpHeader authHeader(String fullUrl, String url, HttpHeader original) { def token = generateToken() return original.with([Authorization: "Bearer $token"]) } private static String generateToken() { return "jwt-token" } } Java In case of JUnit like runners, WebTau uses https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html Service Loaders to locate header providers com.example.tests.junit5.config.HttpAuthHeaderProvider package com.example.tests.junit5.config; import org.testingisdocumenting.webtau.http.HttpHeader; import org.testingisdocumenting.webtau.http.config.WebTauHttpConfiguration; import static org.testingisdocumenting.webtau.WebTauDsl.*; public class HttpAuthHeaderProvider implements WebTauHttpConfiguration { @Override public HttpHeader fullHeader(String fullUrl, String passedUrl, HttpHeader given) { String token = generateToken(); return given.with("Authorization", "Bearer " + token); } private String generateToken() { return "jwt-token"; } } Note: Read persona/HTTP-persona Persona Auth to learn about ways to streamline authentication

Content Type Shortcut

Use http.body to combine Content-Type and payload. Groovy def content = binaryFileContent("path") http.post("/end-point", http.body("application/octet-stream", content)) { // assertions go here } Java byte[] content = binaryFileContent("path"); http.post("/end-point", http.body("application/octet-stream", content), (header, body) -> { // assertions go here }); More examples are in HTTP/body#content-type-shortcuts HTTP Body Content-Type Shortcuts

Response Header

To validate values from response header use header object. Groovy http.post("/end-point") { header.location.should == "http://www.example.org/url/23" header["Location"].should == "http://www.example.org/url/23" header.contentLocation.should == "/url/23" header["Content-Location"].should == "/url/23" header.contentLength.shouldBe > 300 header["Content-Length"].shouldBe > 300 } Java http.post("/end-point", (header, body) -> { header.location.should(equal("http://www.example.org/url/23")); header.get("Location").should(equal("http://www.example.org/url/23")); header.contentLocation.should(equal("/url/23")); header.get("Content-Location").should(equal("/url/23")); header.contentLength.shouldBe(greaterThan(300)); header.get("Content-Length").shouldBe(greaterThan(300)); }); At the moment only location , contentLocation , contentLength have camelCase shortcuts. All the other header values you need to use ['Header-Name'] syntax.