gpt4 book ai didi

com.jetdrone.vertx.yoke.middleware.YokeRequest类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 12:54:40 25 4
gpt4 key购买 nike

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

YokeRequest介绍

[英]YokeRequest is an extension to Vert.x HttpServerRequest with some helper methods to make it easier to perform common tasks related to web application development.
[中]YokeRequest是Vert的扩展。xHttpServerRequest提供了一些辅助方法,可以更轻松地执行与web应用程序开发相关的常见任务。

代码示例

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

public VertxWebContext(YokeRequest request) {
  this.request = request;
  this.response = request.response();
}

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

@Override
  public void handle(JsonObject user) {
    if (user != null) {
      JsonObject session = request.createSession();
      session.put("user", request.getFormAttribute("username"));
      // get the redirect_url parameter
      String redirect = request.getParam("redirect_url", "/");
      request.response().redirect(Utils.decodeURIComponent(redirect));
    } else {
      if (loginTemplate != null) {
        // render internal login
        request.response().setContentType("text/html");
        request.response().setStatusCode(401);
        request.response().end(
            loginTemplate.replace("{title}", (String) request.get("title"))
                .replace("{action}", loginURI + "?redirect_url=" + Utils.encodeURIComponent(request.getParam("redirect_url", "/")))
                .replace("{message}", "Invalid username and/or password, please try again."));
      } else {
        next.handle(401);
      }
    }
  }
});

代码示例来源: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

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

/** 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

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

public HtmlFileTransport(Vertx vertx, Router router, LocalMap<String, SockJSSession> sessions, SockJSHandlerOptions options,
         Handler<SockJSSocket> sockHandler) {
 super(vertx, sessions, options);
 String htmlFileRE = COMMON_PATH_ELEMENT_RE + "htmlfile.*";
 router.get(Pattern.compile(htmlFileRE), (request, next) -> {
  if (log.isTraceEnabled()) log.trace("HtmlFile, get: " + request.uri());
  String callback = request.getParam("callback");
  if (callback == null) {
   callback = request.getParam("c");
   if (callback == null) {
    request.response().setStatusCode(500).end("\"callback\" parameter required\n");
    return;
   }
  }
  String sessionID = request.params().get("param0");
  SockJSSession session = getSession(request, options.getSessionTimeout(), options.getHeartbeatInterval(), sessionID, sockHandler);
  session.setInfo(request.localAddress(), request.remoteAddress(), request.uri(), request.headers());
  session.register(new HtmlFileListener(options.getMaxBytesStreaming(), request, callback, session));
 });
}

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

@Override
public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Object> next) {
  if (request.path().equals(loginURI)) {
    if (HttpMethod.GET.equals(request.method())) {
      if (loginTemplate != null) {
        request.response().setContentType("text/html");
        request.response().end(
            loginTemplate.replace("{title}", (String) request.get("title"))
                .replace("{action}", loginURI + "?redirect_url=" + Utils.encodeURIComponent(request.getParam("redirect_url", "/")))
                .replace("{message}", ""));
      } else {
        request.response().render(userLoginTemplate, next);
    if (HttpMethod.POST.equals(request.method())) {
      if (forceSSL && !request.isSSL()) {
      authHandler.handle(request.getFormAttribute("username"), request.getFormAttribute("password"), new Handler<JsonObject>() {
        @Override
        public void handle(JsonObject user) {
  if (request.path().equals(logoutURI)) {
    if (HttpMethod.GET.equals(request.method())) {
      request.destroySession();
      String redirect = request.getParam("redirect_url", "/");
      request.response().redirect(Utils.decodeURIComponent(redirect));
      return;

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

@Override
  public void handle(Void event) {
    int responseStatus = response().getStatusCode();
    // Only save on success and redirect status codes
    if (responseStatus >= 200 && responseStatus < 400) {
      JsonObject session = get("session");
      if (session != null) {
        store.set(sessionId, session, new Handler<Object>() {
          @Override
          public void handle(Object error) {
            if (error != null) {
              // TODO: better handling of errors
              System.err.println(error);
            }
          }
        });
      }
    }
  }
});

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

@Override
  public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Object> next) {
    JsonObject session = request.get("session");
    if (session != null) {
      if (session.getString("id") != null) {
        next.handle(null);
        return;
      }
    }
    String redirect = request.getParam("redirect_url", Utils.encodeURIComponent(request.uri()));
    request.response().redirect(loginURI + "?redirect_url=" + Utils.decodeURIComponent(redirect));
  }
};

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

next.handle(asyncResult.cause());
} else {
  String accept = request.getHeader("accept", "text/plain");
    request.response().setContentType("text/html");
    request.response().end(
        directoryTemplate.replace("{title}", (String) request.get("title")).replace("{directory}", normalizedDir)
            .replace("{linked-path}", directory.toString())
            .replace("{files}", files.toString()));
    request.response().end(json);
  } else {
    String file;
    request.response().setContentType("text/plain");
    request.response().end(buffer.toString());

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

@Override
public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Object> next) {
  final HttpMethod method = request.method();
  final YokeResponse response = request.response();
  final String accept = request.getHeader("accept-encoding");

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

@Override
public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
  JsonObject session = request.get("session");
    session = request.createSession();
      switch (action.getType()) {
        case REDIRECT:
          request.response().redirect(HttpConstants.TEMP_REDIRECT, action.getLocation());
          break;
        case SUCCESS:
          request.response().setContentType("text/html", "utf-8");
          request.response().end(action.getContent());
          break;
        default:
        request.response().setStatusCode(HttpConstants.UNAUTHORIZED);
        request.response().end(errorPage401);
      } else if (code == HttpConstants.FORBIDDEN) {
        request.response().setStatusCode(HttpConstants.FORBIDDEN);
        request.response().end(errorPage403);
      } else {
        next.handle("Unsupported HTTP action : " + code);

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

@Override
public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Object> next) {
  YokeResponse response = request.response();
    response.setStatusCode(getErrorCode(request.get("error")));
  if (request.get("error") == null) {
    request.put("error", response.getStatusCode());
  String errorMessage = getMessage(request.get("error"));
  int errorCode = response.getStatusCode();
  List<String> stackTrace = getStackTrace(request.get("error"));
  List<String> acceptedMimes = request.sortedHeader("accept");

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

private void handleSend(YokeRequest rc, SockJSSession session) {
 rc.bodyHandler(buff -> {
  String body = buff.toString();
  String ct = rc.getHeader("content-type");
  if ("application/x-www-form-urlencoded".equalsIgnoreCase(ct)) {
   urlEncoded = true;
   urlEncoded = false;
  } else {
   rc.response().setStatusCode(500);
   rc.response().end("Invalid Content-Type");
   return;
   rc.response().setStatusCode(500).end("Payload expected.");
   return;
   sendInvalidJSON(rc.response());
  } else {
   setJSESSIONID(options, rc);
   rc.response().putHeader("Content-Type", "text/plain; charset=UTF-8");
   setNoCacheHeaders(rc);
   rc.response().end("ok");
   if (log.isTraceEnabled()) log.trace("send handled ok");

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

boolean canConsume = false;
for (String c : consumes) {
  if (request.is(c)) {
    canConsume = true;
    break;
String bestContentType = request.accepts(produces);
request.response().setContentType(bestContentType);

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

if (HttpMethod.GET != request.method() && HttpMethod.HEAD != request.method() && HttpMethod.OPTIONS != request.method()) {
  request.setExpectMultipart(true);
  final MultiMap urlEncoded = request.formAttributes();
    if (method != null) {
      urlEncoded.remove(key);
      request.setMethod(HttpMethod.valueOf(method));
      next.handle(null);
      return;
  final JsonObject json = request.body();
  if (json != null) {
    String method = json.getString(key);
    if (method != null) {
      json.remove(key);
      request.setMethod(HttpMethod.valueOf(method));
      next.handle(null);
      return;
String xHttpMethodOverride = request.getHeader("x-http-setmethod-override");
  request.setMethod(HttpMethod.valueOf(xHttpMethodOverride));

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

final HttpMethod method = request.method();
if (HttpMethod.GET == method || HttpMethod.HEAD == method || !request.hasBody()) {
  next.handle(null);
} else {
  final String contentType = request.getHeader("content-type");
  request.setExpectMultipart(true);
    request.uploadHandler(new Handler<HttpServerFileUpload>() {
      @Override
      public void handle(final HttpServerFileUpload fileUpload) {
  request.handler(new Handler<Buffer>() {
    long size = 0;
    final long limit = request.bodyLengthLimit();
  request.endHandler(new Handler<Void>() {
    @Override
    public void handle(Void _void) {

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

@Override
  public void handle(@NotNull YokeRequest request, @NotNull Handler<Object> next) {
    if ("/crossdomain.xml".equals(request.path())) {
      request.response().putHeader("Content-Type", "text/x-cross-domain-policy");
      request.response().end(DATA);
    } else {
      next.handle(null);
    }
  }
}

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

private Object get(final YokeRequest request) throws YokeException {
  switch (type) {
    case 0:
      return request.getParam(isOptional() ? this.path.substring(1) : this.path);
    case 1:
      return request.getFormAttribute(path);
    case 2:
      if (!request.hasBody()) {
        throw new YokeException(400, "No Body");
      Object obj = request.body();
      if (!(obj instanceof JsonObject)) {
        throw new YokeException(400, "Body is not JSON");
      return request.get(path);
    case 4:
      return request.getHeader(path);
    default:
      throw new YokeException(400, "Unknown source " + type);

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