gpt4 book ai didi

com.jetdrone.vertx.yoke.middleware.YokeRequest.getHeader()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 11:56:40 26 4
gpt4 key购买 nike

本文整理了Java中com.jetdrone.vertx.yoke.middleware.YokeRequest.getHeader()方法的一些代码示例,展示了YokeRequest.getHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YokeRequest.getHeader()方法的具体详情如下:
包路径:com.jetdrone.vertx.yoke.middleware.YokeRequest
类名称:YokeRequest
方法名:getHeader

YokeRequest.getHeader介绍

[英]Allow getting headers in a generified way.
[中]

代码示例

代码示例来源:origin: pmlopes/yoke

private HttpServerResponse addCorsResponseHeaders(final YokeRequest request, final YokeResponse response)
{
  final String origin = request.getHeader(ORIGIN);
  return addCorsResponseHeaders(origin, response);
}

代码示例来源:origin: pmlopes/yoke

private boolean isPreflightRequest(final YokeRequest request)
{
  return OPTIONS.name().equals(request.method())
      && (request.getHeader(ACCESS_CONTROL_REQUEST_HEADERS) != null || request.getHeader(ACCESS_CONTROL_REQUEST_METHOD) != null);
}

代码示例来源:origin: pmlopes/yoke

@Override
  public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
    boolean isSecure = (request.isSSL())
        || ("on".equals(request.getHeader("front-end-https")))
        || ("https".equals(request.getHeader("x-forwarded-proto")));

    if (isSecure) {
      request.response().putHeader("Strict-Transport-Security", header);
    }

    next.handle(null);
  }
}

代码示例来源:origin: pmlopes/yoke

public static WebClient detect(YokeRequest req) {
  return detect(req.getHeader("User-Agent"));
}

代码示例来源:origin: pmlopes/yoke

@Override
  public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Object> next) {
    String host = request.getHeader("host");
    if (host == null) {
      next.handle(null);
    } else {
      boolean match = false;
      for (String h : host.split(":")) {
        if (regex.matcher(h).find()) {
          match = true;
          break;
        }
      }

      if (match) {
        handler.handle(request);
      } else {
        next.handle(null);
      }
    }
  }
}

代码示例来源:origin: pmlopes/yoke

/** Read the default locale for this request
 *
 * @return Locale (best match if more than one)
 */
public Locale locale() {
  String languages = getHeader("Accept-Language");
  if (languages != null) {
    // parse
    String[] acceptLanguages = languages.split(" *, *");
    // sort on quality
    Arrays.sort(acceptLanguages, ACCEPT_X_COMPARATOR);
    String bestLanguage = acceptLanguages[0];
    int idx = bestLanguage.indexOf(';');
    if (idx != -1) {
      bestLanguage = bestLanguage.substring(0, idx).trim();
    }
    String[] parts = bestLanguage.split("_|-");
    switch (parts.length) {
      case 3: return new Locale(parts[0], parts[1], parts[2]);
      case 2: return new Locale(parts[0], parts[1]);
      case 1: return new Locale(parts[0]);
    }
  }
  return Locale.getDefault();
}

代码示例来源:origin: pmlopes/yoke

/** Returns the array of accept-? ordered by quality.
 */
public List<String> sortedHeader(@NotNull final String header) {
  String accept = getHeader(header);
  // accept anything when accept is not present
  if (accept == null) {
    return Collections.emptyList();
  }
  // parse
  String[] items = accept.split(" *, *");
  // sort on quality
  Arrays.sort(items, ACCEPT_X_COMPARATOR);
  List<String> list = new ArrayList<>(items.length);
  for (String item : items) {
    // find any ; e.g.: "application/json;q=0.8"
    int space = item.indexOf(';');
    if (space != -1) {
      list.add(item.substring(0, space));
    } else {
      list.add(item);
    }
  }
  return list;
}

代码示例来源:origin: pmlopes/yoke

/** Allow getting headers in a generified way and return defaultValue if the key does not exist.
 *
 * @param name The key to get
 * @param defaultValue value returned when the key does not exist
 * @return {String} The found object
 */
public String getHeader(@NotNull final String name, String defaultValue) {
  if (headers().contains(name)) {
    return getHeader(name);
  } else {
    return defaultValue;
  }
}

代码示例来源:origin: pmlopes/yoke

String ct = getHeader("Content-Type");
if (ct == null) {
  return false;

代码示例来源:origin: pmlopes/yoke

/** Check if the given type(s) is acceptable, returning the best match when true, otherwise null, in which
 * case you should respond with 406 "Not Acceptable".
 *
 * The type value must be a single mime type string such as "application/json" and is validated by checking
 * if the request string starts with it.
 */
public String accepts(@NotNull final String... types) {
  String accept = getHeader("Accept");
  // accept anything when accept is not present
  if (accept == null) {
    return types[0];
  }
  // parse
  String[] acceptTypes = accept.split(" *, *");
  // sort on quality
  Arrays.sort(acceptTypes, ACCEPT_X_COMPARATOR);
  for (String senderAccept : acceptTypes) {
    String[] sAccept = splitMime(senderAccept);
    for (String appAccept : types) {
      String[] aAccept = splitMime(appAccept);
      if (
          (sAccept[0].equals(aAccept[0]) || "*".equals(sAccept[0]) || "*".equals(aAccept[0])) &&
          (sAccept[1].equals(aAccept[1]) || "*".equals(sAccept[1]) || "*".equals(aAccept[1]))) {
        return senderAccept;
      }
    }
  }
  return null;
}

代码示例来源:origin: pmlopes/yoke

@Override
  public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Object> next) {
    String cookieHeader = request.getHeader("cookie");

    if (cookieHeader != null) {
      Set<Cookie> nettyCookies = CookieDecoder.decode(cookieHeader);
      Set<YokeCookie> cookies = new TreeSet<>();

      for (Cookie cookie : nettyCookies) {
        YokeCookie yokeCookie = new YokeCookie(cookie, mac);
        String value = yokeCookie.getUnsignedValue();
        // value cannot be null in a cookie if the signature is mismatch then this value will be null
        // in that case the cookie has been tampered
        if (value == null) {
          next.handle(400);
          return;
        }
        cookies.add(yokeCookie);
      }

      request.setCookies(cookies);
    }

    next.handle(null);
  }
}

代码示例来源:origin: pmlopes/yoke

/** Returns the ip address of the client, when trust-proxy is true (default) then first look into X-Forward-For
 * Header */
public String ip() {
  Boolean trustProxy = (Boolean) context.get("trust-proxy");
  if (trustProxy != null && trustProxy) {
    String xForwardFor = getHeader("x-forward-for");
    if (xForwardFor != null) {
      String[] ips = xForwardFor.split(" *, *");
      if (ips.length > 0) {
        return ips[0];
      }
    }
  }
  return request.remoteAddress().host();
}

代码示例来源:origin: pmlopes/yoke

static void setJSESSIONID(SockJSHandlerOptions options, YokeRequest request) {
 String cookies = request.getHeader("cookie");
 if (options.isInsertJSESSIONID()) {
  //Preserve existing JSESSIONID, if any
  if (cookies != null) {
   String[] parts;
   if (cookies.contains(";")) {
    parts = cookies.split(";");
   } else {
    parts = new String[] {cookies};
   }
   for (String part: parts) {
    if (part.startsWith("JSESSIONID")) {
     cookies = part + "; path=/";
     break;
    }
   }
  }
  if (cookies == null) {
   cookies = "JSESSIONID=dummy; path=/";
  }
  request.response().putHeader("Set-Cookie", cookies);
 }
}

代码示例来源:origin: pmlopes/yoke

@Override
  public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
    final WebClient webClient = WebClient.detect(request.getHeader("user-agent"));

    boolean isIE = webClient.getUserAgent() == WebClient.UserAgent.IE;
    int majorVersion = webClient.getMajorVersion();

    String value;

    if ((!isIE) || (majorVersion >= 9) || (setOnOldIE)) {
      value = "1; mode=block";
    } else {
      value = "0";
    }

    request.response().putHeader("X-XSS-Protection", value);
    next.handle(null);
  }
}

代码示例来源:origin: pmlopes/yoke

private void handlePreflightRequest(final YokeRequest request)
{
  if (isValidOrigin(request.getHeader(ORIGIN)))
  {
    addCorsResponseHeaders(request.getHeader(ORIGIN),
      request.response().setStatusCode(204).setStatusMessage("No Content")).end();
  }
  else
  {
    request.response().setStatusCode(403).setStatusMessage("CORS Rejected").end();
  }
}

代码示例来源:origin: pmlopes/yoke

final String accept = request.getHeader("accept-encoding");

代码示例来源:origin: pmlopes/yoke

@Override
 public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
  try {
   if (log.isTraceEnabled()) log.trace("In Iframe handler");
   if (etag != null && etag.equals(request.getHeader("if-none-match"))) {
    request.response().setStatusCode(304);
    request.response().end();
   } else {
    long oneYear = 365 * 24 * 60 * 60 * 1000L;
    String expires = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(new Date(System.currentTimeMillis() + oneYear));
    request.response().putHeader("Content-Type", "text/html; charset=UTF-8")
      .putHeader("Cache-Control", "public,max-age=31536000")
      .putHeader("Expires", expires).putHeader("ETag", etag).end(iframeHTML);
   }
  } catch (Exception e) {
   log.error("Failed to server iframe", e);
  }
 }
};

代码示例来源:origin: pmlopes/yoke

return request.get(path);
case 4:
  return request.getHeader(path);
default:
  throw new YokeException(400, "Unknown source " + type);

代码示例来源:origin: pmlopes/yoke

String xHttpMethodOverride = request.getHeader("x-http-setmethod-override");

代码示例来源:origin: pmlopes/yoke

String ct = rc.getHeader("content-type");
if ("application/x-www-form-urlencoded".equalsIgnoreCase(ct)) {
 urlEncoded = true;

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com