Java Code Examples for io.vertx.core.MultiMap#remove()

The following examples show how to use io.vertx.core.MultiMap#remove() . 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: VertxRequestTransmitter.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
private void renameHeader(
    final MultiMap headers, final String oldHeader, final String newHeader) {
  final String oldHeaderValue = headers.get(oldHeader);
  headers.remove(oldHeader);
  if (oldHeaderValue != null) {
    headers.add(newHeader, oldHeaderValue);
  }
}
 
Example 2
Source File: SwaggerRouter.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
private static void manageHeaders(HttpServerResponse httpServerResponse, MultiMap messageHeaders) {
    if(messageHeaders.contains(CUSTOM_STATUS_CODE_HEADER_KEY)) {
        Integer customStatusCode = Integer.valueOf(messageHeaders.get(CUSTOM_STATUS_CODE_HEADER_KEY));
        httpServerResponse.setStatusCode(customStatusCode);
        messageHeaders.remove(CUSTOM_STATUS_CODE_HEADER_KEY);
    }
    if(messageHeaders.contains(CUSTOM_STATUS_MESSAGE_HEADER_KEY)) {
        String customStatusMessage = messageHeaders.get(CUSTOM_STATUS_MESSAGE_HEADER_KEY);
        httpServerResponse.setStatusMessage(customStatusMessage);
        messageHeaders.remove(CUSTOM_STATUS_MESSAGE_HEADER_KEY);
    }
    httpServerResponse.headers().addAll(messageHeaders);
}
 
Example 3
Source File: ProxyService.java    From okapi with Apache License 2.0 5 votes vote down vote up
/**
 * Remove all headers that are only used between Okapi and mod-authtoken.
 *
 * @param headers request or response HTTP headers
 */
private void sanitizeAuthHeaders(MultiMap headers) {
  headers.remove(XOkapiHeaders.MODULE_TOKENS);
  headers.remove(XOkapiHeaders.MODULE_PERMISSIONS);
  headers.remove(XOkapiHeaders.PERMISSIONS_REQUIRED);
  headers.remove(XOkapiHeaders.PERMISSIONS_DESIRED);
  headers.remove(XOkapiHeaders.EXTRA_PERMISSIONS);
  headers.remove(XOkapiHeaders.FILTER);
}
 
Example 4
Source File: ProxyService.java    From okapi with Apache License 2.0 5 votes vote down vote up
private void fixupXOkapiToken(ModuleDescriptor md, MultiMap reqHeaders, MultiMap resHeaders) {
  String reqToken = reqHeaders.get(XOkapiHeaders.TOKEN);
  String resToken = resHeaders.get(XOkapiHeaders.TOKEN);
  if (resToken != null) {
    if (resToken.equals(reqToken)) {
      logger.warn("Removing X-Okapi-Token returned by module {} (RMB-478)", md.getId());
      resHeaders.remove(XOkapiHeaders.TOKEN);
    } else {
      logger.info("New X-Okapi-Token returned by module {}", md.getId());
    }
  }
}
 
Example 5
Source File: MailEncoder.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
/**
 * create the headers of the MIME message by combining the headers the user has supplied with the ones necessary for
 * the message
 *
 * @return MultiMap of final headers
 */
private MultiMap createHeaders(MultiMap additionalHeaders) {
  MultiMap headers = MultiMap.caseInsensitiveMultiMap();;

  if (!message.isFixedHeaders()) {
    headers.set("MIME-Version", "1.0");
    headers.set("Message-ID", Utils.generateMessageID(hostname, userAgent));
    headers.set("Date", Utils.generateDate());

    if (message.getSubject() != null) {
      headers.set("Subject", Utils.encodeHeader(message.getSubject(), 9));
    }

    if (message.getFrom() != null) {
      headers.set("From", Utils.encodeHeaderEmail(message.getFrom(), 6));
    }
    if (message.getTo() != null) {
      headers.set("To", Utils.encodeEmailList(message.getTo(), 4));
    }
    if (message.getCc() != null) {
      headers.set("Cc", Utils.encodeEmailList(message.getCc(), 4));
    }

    headers.addAll(additionalHeaders);
  }

  // add the user-supplied headers as last step, this way it is possible
  // to supply a custom Message-ID for example.
  MultiMap headersToSet = message.getHeaders();
  if (headersToSet != null) {
    for (String key : headersToSet.names()) {
      headers.remove(key);
    }
    headers.addAll(headersToSet);
  }

  messageID = headers.get("Message-ID");
  
  return headers;
}
 
Example 6
Source File: BaseTransport.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
static MultiMap removeCookieHeaders(MultiMap headers) {
  // We don't want to remove the JSESSION cookie.
  String cookieHeader = headers.get(COOKIE);
  if (cookieHeader != null) {
    headers.remove(COOKIE);
    Set<Cookie> nettyCookies = ServerCookieDecoder.STRICT.decode(cookieHeader);
    for (Cookie cookie: nettyCookies) {
      if (cookie.name().equals("JSESSIONID")) {
        headers.add(COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
        break;
      }
    }
  }
  return headers;
}
 
Example 7
Source File: VertxRequestTransmitter.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
private MultiMap createHeaders(final MultiMap headers) {
  final MultiMap requestHeaders = new VertxHttpHeaders();
  requestHeaders.addAll(headers);
  requestHeaders.remove(HttpHeaders.CONTENT_LENGTH);
  requestHeaders.remove(HttpHeaders.ORIGIN);
  renameHeader(requestHeaders, HttpHeaders.HOST, HttpHeaders.X_FORWARDED_HOST);
  return requestHeaders;
}
 
Example 8
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
/**
 * Add cookie object with form style and not exploded
 *
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 | form           | false   | query, cookie | color=blue,black,brown              | color=R,100,G,200,B,150                |
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 *
 * @param paramName
 * @param values
 */
private void renderCookieObjectForm(String paramName, Map<String, Object> values, MultiMap map) {
    List<String> listToSerialize = new ArrayList<>();
    for (Map.Entry<String, Object> entry : values.entrySet()) {
        listToSerialize.add(entry.getKey());
        listToSerialize.add(String.valueOf(entry.getValue()));
    }
    String value = String.join(",", listToSerialize);
    map.remove(paramName);
    map.add(paramName, value);
}
 
Example 9
Source File: ApiClient.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
/**
 * Add cookie object with form style and not exploded
 *
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 | form           | false   | query, cookie | color=blue,black,brown              | color=R,100,G,200,B,150                |
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 *
 * @param paramName
 * @param values
 */
private void renderCookieObjectForm(String paramName, Map<String, Object> values, MultiMap map) {
    List<String> listToSerialize = new ArrayList<>();
    for (Map.Entry<String, Object> entry : values.entrySet()) {
        listToSerialize.add(entry.getKey());
        listToSerialize.add(String.valueOf(entry.getValue()));
    }
    String value = String.join(",", listToSerialize);
    map.remove(paramName);
    map.add(paramName, value);
}
 
Example 10
Source File: ProxyService.java    From okapi with Apache License 2.0 4 votes vote down vote up
private void passFilterHeaders(RoutingContext ctx, ProxyContext pc, ModuleInstance mi) {
  // Pass the X-Okapi-Filter header for filters (only)
  // And all kind of things for the auth filter
  MultiMap headers = ctx.request().headers();
  headers.remove(XOkapiHeaders.FILTER);

  final String phase = mi.getRoutingEntry().getPhase();
  if (phase != null) {
    String pth = mi.getRoutingEntry().getPathPattern();
    if (pth == null) {
      pth = mi.getRoutingEntry().getPath();
    }
    String filt = mi.getRoutingEntry().getPhase() + " " + pth;
    pc.debug("Adding " + XOkapiHeaders.FILTER + ": " + filt);
    // The auth filter needs all kinds of special headers
    headers.add(XOkapiHeaders.FILTER, filt);

    boolean badAuth = pc.getAuthRes() != 0 && (pc.getAuthRes() < 200 || pc.getAuthRes() >= 300);
    switch (phase) {
      case XOkapiHeaders.FILTER_AUTH:
        authHeaders(pc.getModList(), headers, pc);
        break;
      case XOkapiHeaders.FILTER_PRE:
        // pass request headers and failed auth result
        if (badAuth) {
          headers.add(XOkapiHeaders.AUTH_RESULT, "" + pc.getAuthRes());
        }
        break;
      case XOkapiHeaders.FILTER_POST:
        // pass request headers and failed handler/auth result
        if (pc.getHandlerRes() > 0) {
          String hresult = String.valueOf(pc.getHandlerRes());
          headers.set(XOkapiHeaders.HANDLER_RESULT, hresult);
          headers.set(XOkapiHeaders.HANDLER_HEADERS, Json.encode(pc.getHandlerHeaders()));
        } else if (badAuth) {
          headers.set(XOkapiHeaders.AUTH_RESULT, "" + pc.getAuthRes());
          headers.set(XOkapiHeaders.AUTH_HEADERS, Json.encode(pc.getAuthHeaders()));
        } else {
          logger.warn("proxyR: postHeader: Oops, no result to pass to post handler");
        }
        break;
      default:
        logger.error("Not supported phase: {}", phase);
        break;
    }
  }
}
 
Example 11
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
private void renderCookieParam(String paramName, Object value, MultiMap map) {
    map.remove(paramName);
    map.add(paramName, String.valueOf(value));
}
 
Example 12
Source File: ApiClient.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
private void renderCookieParam(String paramName, Object value, MultiMap map) {
    map.remove(paramName);
    map.add(paramName, String.valueOf(value));
}
 
Example 13
Source File: ApiClient.java    From vertx-web with Apache License 2.0 3 votes vote down vote up
/**
 * Add cookie object with form style and exploded
 *
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 | form           | true    | query, cookie | color=blue&color=black&color=brown  | R=100&G=200&B=150                      |
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 *
 * @param paramName
 * @param values
 */
private void renderCookieObjectFormExplode(String paramName, Map<String, Object> values, MultiMap map) {
    for (Map.Entry<String, Object> value : values.entrySet()) {
        map.remove(value.getKey());
        map.add(value.getKey(), String.valueOf(value.getValue()));
    }
}
 
Example 14
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 3 votes vote down vote up
/**
 * Add cookie object with form style and exploded
 *
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 | form           | true    | query, cookie | color=blue&color=black&color=brown  | R=100&G=200&B=150                      |
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 *
 * @param paramName
 * @param values
 */
private void renderCookieObjectFormExplode(String paramName, Map<String, Object> values, MultiMap map) {
    for (Map.Entry<String, Object> value : values.entrySet()) {
        map.remove(value.getKey());
        map.add(value.getKey(), String.valueOf(value.getValue()));
    }
}
 
Example 15
Source File: ApiClient.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Add cookie array with form style and not exploded
 *
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 | form           | false   | query, cookie | color=blue,black,brown              | color=R,100,G,200,B,150                |
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 *
 * @param paramName
 * @param values
 */
private void renderCookieArrayForm(String paramName, List<Object> values, MultiMap map) {
    String value = String.join(",", values.stream().map(String::valueOf).collect(Collectors.toList()));
    map.remove(paramName);
    map.add(paramName, value);
}
 
Example 16
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Add cookie array with form style and exploded
 *
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 | form           | true    | query, cookie | color=blue&color=black&color=brown  | R=100&G=200&B=150                      |
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 *
 * @param paramName
 * @param values
 */
private void renderCookieArrayFormExplode(String paramName, List<Object> values, MultiMap map) {
    map.remove(paramName);
    for (Object value : values)
        map.add(paramName, String.valueOf(value));
}
 
Example 17
Source File: ApiClient.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Add cookie array with form style and exploded
 *
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 | form           | true    | query, cookie | color=blue&color=black&color=brown  | R=100&G=200&B=150                      |
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 *
 * @param paramName
 * @param values
 */
private void renderCookieArrayFormExplode(String paramName, List<Object> values, MultiMap map) {
    map.remove(paramName);
    for (Object value : values)
        map.add(paramName, String.valueOf(value));
}
 
Example 18
Source File: ParametersTestAPIClient.java    From vertx-web with Apache License 2.0 2 votes vote down vote up
/**
 * Add cookie array with form style and not exploded
 *
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 | form           | false   | query, cookie | color=blue,black,brown              | color=R,100,G,200,B,150                |
 +----------------+---------+---------------+-------------------------------------+----------------------------------------+
 *
 * @param paramName
 * @param values
 */
private void renderCookieArrayForm(String paramName, List<Object> values, MultiMap map) {
    String value = String.join(",", values.stream().map(String::valueOf).collect(Collectors.toList()));
    map.remove(paramName);
    map.add(paramName, value);
}