HttpResponse.withHeader
Code IndexAdd Codota to your IDE (free)

Best code snippets using org.mockserver.model.HttpResponse.withHeader(Showing top 13 results out of 315)

origin: jamesdbloom/mockserver

private void setHeaderIfNotAlreadyExists(HttpResponse response, String name, String value) {
  if (response.getFirstHeader(name).isEmpty()) {
    response.withHeader(name, value);
  }
}
origin: jamesdbloom/mockserver

public void responseLiteralWithUTF16BodyResponse() {
  new MockServerClient("localhost", 1080)
    // this request matcher matches every request
    .when(
      request()
    )
    .respond(
      response()
        .withHeader(
          CONTENT_TYPE.toString(),
          MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString()
        )
        .withBody("我说中国话".getBytes(Charsets.UTF_16))
    );
}
origin: jamesdbloom/mockserver

@Override
public void writeResponse(HttpRequest request, HttpResponse response, boolean apiResponse) {
  if (response == null) {
    response = notFoundResponse();
  }
  if (enableCORSForAllResponses()) {
    addCORSHeaders.addCORSHeaders(request, response);
  } else if (apiResponse && enableCORSForAPI()) {
    addCORSHeaders.addCORSHeaders(request, response);
  }
  if (apiResponse) {
    response.withHeader("version", org.mockserver.Version.getVersion());
  }
  addConnectionHeader(request, response);
  writeAndCloseSocket(ctx, request, response);
}
origin: jamesdbloom/mockserver

@Override
public void writeResponse(HttpRequest request, HttpResponse response, boolean apiResponse) {
  if (response == null) {
    response = notFoundResponse();
  }
  if (enableCORSForAllResponses()) {
    addCORSHeaders.addCORSHeaders(request, response);
  } else if (apiResponse && enableCORSForAPI()) {
    addCORSHeaders.addCORSHeaders(request, response);
  }
  if (apiResponse) {
    response.withHeader("version", org.mockserver.Version.getVersion());
  }
  addConnectionHeader(request, response);
  mockServerResponseToHttpServletResponseEncoder.mapMockServerResponseToHttpServletResponse(response, httpServletResponse);
}
origin: jamesdbloom/mockserver

.withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())
.withStatusCode(OK_200.code())
.withReasonPhrase(OK_200.reasonPhrase())
.withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_16).toString())
.withStatusCode(OK_200.code())
.withReasonPhrase(OK_200.reasonPhrase())
origin: jamesdbloom/mockserver

.withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())
.withStatusCode(OK_200.code())
.withReasonPhrase(OK_200.reasonPhrase())
.withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())
.withStatusCode(OK_200.code())
.withReasonPhrase(OK_200.reasonPhrase())
origin: org.mock-server/mockserver-core

  public void addCORSHeaders(HttpResponse response) {
    String methods = "CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PUT, TRACE";
    String headers = "Allow, Content-Encoding, Content-Length, Content-Type, ETag, Expires, Last-Modified, Location, Server, Vary";
    if (response.getFirstHeader("Access-Control-Allow-Origin").isEmpty()) {
      response.withHeader("Access-Control-Allow-Origin", "*");
    }
    if (response.getFirstHeader("Access-Control-Allow-Methods").isEmpty()) {
      response.withHeader("Access-Control-Allow-Methods", methods);
    }
    if (response.getFirstHeader("Access-Control-Allow-Headers").isEmpty()) {
      response.withHeader("Access-Control-Allow-Headers", headers);
    }
    if (response.getFirstHeader("Access-Control-Expose-Headers").isEmpty()) {
      response.withHeader("Access-Control-Expose-Headers", headers);
    }
    if (response.getFirstHeader("Access-Control-Max-Age").isEmpty()) {
      response.withHeader("Access-Control-Max-Age", "300");
    }
    if (response.getFirstHeader("X-CORS").isEmpty()) {
      response.withHeader("X-CORS", "MockServer CORS support enabled by default, to disable ConfigurationProperties.enableCORSForAPI(false) or -Dmockserver.disableCORS=false");
    }
  }
}
origin: jamesdbloom/mockserver

  .withStatusCode(OK_200.code())
  .withReasonPhrase(OK_200.reasonPhrase())
  .withHeader("name", "value")
  .withBody("some_request_body"),
makeRequest(
  .withStatusCode(OK_200.code())
  .withReasonPhrase(OK_200.reasonPhrase())
  .withHeader("name", "value")
  .withBody("some_request_body"),
makeRequest(
origin: jamesdbloom/mockserver

assertEquals(
  response("some_body_one")
    .withHeader("some", "header")
    .withHeader("cookie", "some=parameter")
    .withHeader("set-cookie", "some=parameter")
    .withCookie("some", "parameter"),
  makeRequest(
origin: jamesdbloom/mockserver

    .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())
    .withBody(body)
);
  .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())
  .withStatusCode(OK_200.code())
  .withReasonPhrase(OK_200.reasonPhrase())
  .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())
  .withStatusCode(OK_200.code())
  .withReasonPhrase(OK_200.reasonPhrase())
origin: jamesdbloom/mockserver

  .withReasonPhrase(OK_200.reasonPhrase())
  .withCookie("name", "value")
  .withHeader("set-cookie", "name=value")
  .withBody("{\"method\":\"GET\",\"path\":\"/some_path\",\"body\":\"some_request_body\"}"),
makeRequest(
  .withReasonPhrase(OK_200.reasonPhrase())
  .withCookie("name", "value")
  .withHeader("set-cookie", "name=value")
  .withBody("{\"method\":\"GET\",\"path\":\"/some_path\",\"body\":\"some_request_body\"}"),
makeRequest(
origin: jamesdbloom/mockserver

.withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())
.withStatusCode(OK_200.code())
.withReasonPhrase(OK_200.reasonPhrase())
.withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(Charsets.UTF_8).toString())
.withStatusCode(OK_200.code())
.withReasonPhrase(OK_200.reasonPhrase())
origin: org.mock-server/mockserver-core

  public void addCORSHeaders(HttpResponse response) {
    String methods = "CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PUT, TRACE";
    String headers = "Allow, Content-Encoding, Content-Length, Content-Type, ETag, Expires, Last-Modified, Location, Server, Vary";
    if (response.getFirstHeader("Access-Control-Allow-Origin").isEmpty()) {
      response.withHeader("Access-Control-Allow-Origin", "*");
    }
    if (response.getFirstHeader("Access-Control-Allow-Methods").isEmpty()) {
      response.withHeader("Access-Control-Allow-Methods", methods);
    }
    if (response.getFirstHeader("Access-Control-Allow-Headers").isEmpty()) {
      response.withHeader("Access-Control-Allow-Headers", headers);
    }
    if (response.getFirstHeader("Access-Control-Expose-Headers").isEmpty()) {
      response.withHeader("Access-Control-Expose-Headers", headers);
    }
    if (response.getFirstHeader("Access-Control-Max-Age").isEmpty()) {
      response.withHeader("Access-Control-Max-Age", "300");
    }
    if (response.getFirstHeader("X-CORS").isEmpty()) {
      response.withHeader("X-CORS", "MockServer CORS support enabled by default, to disable ConfigurationProperties.enableCORSForAPI(false) or -Dmockserver.disableCORS=false");
    }
  }
}
org.mockserver.modelHttpResponsewithHeader

Javadoc

Add a header to return as a Header object, if a header with the same name already exists this will NOT be modified but two headers will exist

Popular methods of HttpResponse

  • response
    Static builder to create a response with a 200 status code and the string response body.
  • withBody
    Set response body to return as binary such as a pdf or image
  • withStatusCode
    The status code to return, such as 200, 404, the status code specified here will result in the defau
  • notFoundResponse
    Static builder to create a not found response.
  • withReasonPhrase
    The reason phrase to return, if no reason code is returned this will be defaulted to the standard re
  • getBodyAsString
  • getStatusCode
  • withDelay
    The delay before responding with this request as a Delay object, for example new Delay(TimeUnit.SECO
  • withHeaders
    The headers to return as a varargs of Header objects
  • getBody
  • getConnectionOptions
  • getFirstHeader
  • getConnectionOptions,
  • getFirstHeader,
  • getHeaderList,
  • replaceHeader,
  • withConnectionOptions,
  • withCookies,
  • <init>,
  • applyDelay,
  • clone

Popular classes and methods

  • setScale (BigDecimal)
    Returns a new BigDecimal instance with the specified scale. If the new scale is greater than the old
  • requestLocationUpdates (LocationManager)
  • getExternalFilesDir (Context)
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • RandomAccessFile (java.io)
    Saves binary data to the local storage; currently using hex encoding. The string is prefixed with "h
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • TreeMap (java.util)
    A map whose entries are sorted by their keys. All optional operations such as #put and #remove are s
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)