org.jooby.Request.accepts()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(423)

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

Request.accepts介绍

[英]Check if the given types are acceptable, returning the best match when true, or else Optional.empty.

// Accept: text/html 
req.accepts("text/html"); 
//  
 => "text/html" 
// Accept: text/*, application/json 
req.accepts("text/html"); 
//  
 => "text/html" 
req.accepts("text/html"); 
//  
 => "text/html" 
req.accepts("application/json" "text/plain"); 
//  
 => "application/json" 
req.accepts("application/json"); 
//  
 => "application/json" 
// Accept: text/*, application/json 
req.accepts("image/png"); 
//  
 => Optional.empty 
// Accept: text/*;q=.5, application/json 
req.accepts("text/html", "application/json"); 
//  
 => "application/json"

[中]检查给定类型是否可接受,如果为true,则返回最佳匹配,否则为可选。空的

// Accept: text/html 
req.accepts("text/html"); 
//  
 => "text/html" 
// Accept: text/*, application/json 
req.accepts("text/html"); 
//  
 => "text/html" 
req.accepts("text/html"); 
//  
 => "text/html" 
req.accepts("application/json" "text/plain"); 
//  
 => "application/json" 
req.accepts("application/json"); 
//  
 => "application/json" 
// Accept: text/*, application/json 
req.accepts("image/png"); 
//  
 => Optional.empty 
// Accept: text/*;q=.5, application/json 
req.accepts("text/html", "application/json"); 
//  
 => "application/json"

代码示例

代码示例来源:origin: jooby-project/jooby

@Override
public Optional<MediaType> accepts(final MediaType... types) {
 return req.accepts(types);
}

代码示例来源:origin: jooby-project/jooby

@Override
public Optional<MediaType> accepts(final String... types) {
 return req.accepts(types);
}

代码示例来源:origin: jooby-project/jooby

@Override
public Optional<MediaType> accepts(final List<MediaType> types) {
 return req.accepts(types);
}

代码示例来源:origin: jooby-project/jooby

/**
 * True, if request accept any of the given types.
 *
 * @param types Types to test
 * @return True if any of the given type is accepted.
 */
default boolean is(final List<MediaType> types) {
 return accepts(types).isPresent();
}

代码示例来源:origin: jooby-project/jooby

/**
 * True, if request accept any of the given types.
 *
 * @param types Types to test
 * @return True if any of the given type is accepted.
 */
default boolean is(final MediaType... types) {
 return accepts(types).isPresent();
}

代码示例来源:origin: jooby-project/jooby

/**
 * True, if request accept any of the given types.
 *
 * @param types Types to test
 * @return True if any of the given type is accepted.
 */
default boolean is(final String... types) {
 return accepts(types).isPresent();
}

代码示例来源:origin: jooby-project/jooby

return accepts(ImmutableList.copyOf(types));

代码示例来源:origin: jooby-project/jooby

return accepts(MediaType.valueOf(types));

代码示例来源:origin: jooby-project/jooby

if (req.accepts(MediaType.html).isPresent()) {

代码示例来源:origin: jooby-project/jooby

static void install(final Env env, final Config conf) {
 String path = conf.getString("crash.httpshell.path");
 Router router = env.router();
 router.get(path + "/{cmd:.*}", router.promise("direct", (req, deferred) -> {
  MediaType type = req.accepts(MediaType.json)
    .map(it -> MediaType.json)
    .orElse(MediaType.html);
  PluginContext ctx = req.require(PluginContext.class);
  ShellFactory shellFactory = ctx.getPlugin(ShellFactory.class);
  Shell shell = shellFactory.create(null);
  String cmd = req.param("cmd").value().replaceAll("/", " ");
  ShellProcess process = shell.createProcess(cmd);
  ShellProcessContext spc = new SimpleProcessContext(
    result -> deferred.resolve(result.type(type)));
  process.execute(spc);
 }));
}

代码示例来源:origin: org.jooby/jooby

@Override
public Optional<MediaType> accepts(final MediaType... types) {
 return req.accepts(types);
}

代码示例来源:origin: org.jooby/jooby

@Override
public Optional<MediaType> accepts(final List<MediaType> types) {
 return req.accepts(types);
}

代码示例来源:origin: org.jooby/jooby

@Override
public Optional<MediaType> accepts(final String... types) {
 return req.accepts(types);
}

代码示例来源:origin: org.jooby/jooby

/**
 * True, if request accept any of the given types.
 *
 * @param types Types to test
 * @return True if any of the given type is accepted.
 */
default boolean is(final MediaType... types) {
 return accepts(types).isPresent();
}

代码示例来源:origin: org.jooby/jooby

/**
 * True, if request accept any of the given types.
 *
 * @param types Types to test
 * @return True if any of the given type is accepted.
 */
default boolean is(final String... types) {
 return accepts(types).isPresent();
}

代码示例来源:origin: org.jooby/jooby

/**
 * True, if request accept any of the given types.
 *
 * @param types Types to test
 * @return True if any of the given type is accepted.
 */
default boolean is(final List<MediaType> types) {
 return accepts(types).isPresent();
}

代码示例来源:origin: org.jooby/jooby

return accepts(ImmutableList.copyOf(types));

代码示例来源:origin: org.jooby/jooby

return accepts(MediaType.valueOf(types));

代码示例来源:origin: org.jooby/jooby-whoops

if (req.accepts(MediaType.html).isPresent()) {

相关文章