Java Code Examples for io.vertx.core.http.HttpServerResponse#headers()

The following examples show how to use io.vertx.core.http.HttpServerResponse#headers() . 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: Api.java    From xyz-hub with Apache License 2.0 6 votes vote down vote up
/**
 * Internally used to send a "Not Modified" response when appropriate. In any case this method will set the e-tag header, if the task
 * response has generated an e-tag.
 *
 * @param task the task for which to generate the "Not Modified" response.
 * @return true if a response has been send; false if not.
 */
private boolean sendNotModifiedResponseIfNoneMatch(final Task task) {
  //If the task has an ETag, set it in the HTTP header.
  //Set the ETag header
  if (task.getEtag() != null) {
    final RoutingContext context = task.context;
    final HttpServerResponse httpResponse = context.response();
    final MultiMap httpHeaders = httpResponse.headers();

    httpHeaders.add(HttpHeaders.ETAG, task.getEtag());

    //If the ETag didn't change, return "Not Modified"
    if (task.etagMatches()) {
      sendResponse(task, NOT_MODIFIED, null, null);
      return true;
    }
  }

  return false;
}
 
Example 2
Source File: ResponseHeaderAccessItem.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public void appendServerFormattedItem(ServerAccessLogEvent accessLogEvent, StringBuilder builder) {
  HttpServerResponse response = accessLogEvent.getRoutingContext().response();
  if (null == response || null == response.headers() || StringUtils.isEmpty(response.headers().get(varName))) {
    builder.append(RESULT_NOT_FOUND);
    return;
  }
  builder.append(response.headers().get(varName));
}
 
Example 3
Source File: App.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void handlePlainText(HttpServerRequest request) {
  HttpServerResponse response = request.response();
  MultiMap headers = response.headers();
  for (int i = 0;i < plaintextHeaders.length; i+= 2) {
    headers.add(plaintextHeaders[i], plaintextHeaders[i + 1]);
  }
  response.end(HELLO_WORLD_BUFFER);
}
 
Example 4
Source File: App.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void handleJson(HttpServerRequest request) {
  HttpServerResponse response = request.response();
  MultiMap headers = response.headers();
  headers
      .add(HEADER_CONTENT_TYPE, RESPONSE_TYPE_JSON)
      .add(HEADER_SERVER, SERVER)
      .add(HEADER_DATE, dateString);
  response.end(new Message("Hello, World!").toBuffer());
}