Java Code Examples for org.openqa.selenium.remote.http.HttpResponse#addHeader()

The following examples show how to use org.openqa.selenium.remote.http.HttpResponse#addHeader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddWebDriverSpecHeaders.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Override
public HttpHandler apply(HttpHandler next) {
  return req -> {
    HttpResponse res = next.execute(req);
    if (res == null) {
      return res;
    }

    if (res.getHeader("Content-Type") == null) {
      res.addHeader("Content-Type", JSON_UTF_8.toString());
    }
    if (res.getHeader("Cache-Control") == null) {
      res.addHeader("Cache-Control", "none");
    }

    return res;
  };
}
 
Example 2
Source File: WrapExceptions.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Override
public HttpHandler apply(HttpHandler next) {
  return req -> {
    try {
      return next.execute(req);
    } catch (Throwable cause) {
      HttpResponse res = new HttpResponse();
      res.setStatus(errors.getHttpStatusCode(cause));

      res.addHeader("Content-Type", JSON_UTF_8.toString());
      res.addHeader("Cache-Control", "none");

      res.setContent(asJson(errors.encode(cause)));

      return res;
    }
  };
}
 
Example 3
Source File: W3CHttpResponseCodecTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
private HttpResponse createValidResponse(int statusCode, Map<String, ?> data) {
  byte[] contents = new Json().toJson(data).getBytes(UTF_8);

  HttpResponse response = new HttpResponse();
  response.setStatus(statusCode);
  response.addHeader("Content-Type", "application/json; charset=utf-8");
  response.addHeader("Cache-Control", "no-cache");
  response.addHeader("Content-Length", String.valueOf(contents.length));
  response.setContent(bytes(contents));

  return response;
}