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

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

本文整理了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.

  1. // Accept: text/html
  2. req.accepts("text/html");
  3. //
  4. => "text/html"
  5. // Accept: text/*, application/json
  6. req.accepts("text/html");
  7. //
  8. => "text/html"
  9. req.accepts("text/html");
  10. //
  11. => "text/html"
  12. req.accepts("application/json" "text/plain");
  13. //
  14. => "application/json"
  15. req.accepts("application/json");
  16. //
  17. => "application/json"
  18. // Accept: text/*, application/json
  19. req.accepts("image/png");
  20. //
  21. => Optional.empty
  22. // Accept: text/*;q=.5, application/json
  23. req.accepts("text/html", "application/json");
  24. //
  25. => "application/json"

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

  1. // Accept: text/html
  2. req.accepts("text/html");
  3. //
  4. => "text/html"
  5. // Accept: text/*, application/json
  6. req.accepts("text/html");
  7. //
  8. => "text/html"
  9. req.accepts("text/html");
  10. //
  11. => "text/html"
  12. req.accepts("application/json" "text/plain");
  13. //
  14. => "application/json"
  15. req.accepts("application/json");
  16. //
  17. => "application/json"
  18. // Accept: text/*, application/json
  19. req.accepts("image/png");
  20. //
  21. => Optional.empty
  22. // Accept: text/*;q=.5, application/json
  23. req.accepts("text/html", "application/json");
  24. //
  25. => "application/json"

代码示例

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

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

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

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

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

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

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

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

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

  1. /**
  2. * True, if request accept any of the given types.
  3. *
  4. * @param types Types to test
  5. * @return True if any of the given type is accepted.
  6. */
  7. default boolean is(final MediaType... types) {
  8. return accepts(types).isPresent();
  9. }

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

  1. /**
  2. * True, if request accept any of the given types.
  3. *
  4. * @param types Types to test
  5. * @return True if any of the given type is accepted.
  6. */
  7. default boolean is(final String... types) {
  8. return accepts(types).isPresent();
  9. }

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

  1. return accepts(ImmutableList.copyOf(types));

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

  1. return accepts(MediaType.valueOf(types));

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * True, if request accept any of the given types.
  3. *
  4. * @param types Types to test
  5. * @return True if any of the given type is accepted.
  6. */
  7. default boolean is(final MediaType... types) {
  8. return accepts(types).isPresent();
  9. }

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

  1. /**
  2. * True, if request accept any of the given types.
  3. *
  4. * @param types Types to test
  5. * @return True if any of the given type is accepted.
  6. */
  7. default boolean is(final String... types) {
  8. return accepts(types).isPresent();
  9. }

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

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

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

  1. return accepts(ImmutableList.copyOf(types));

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

  1. return accepts(MediaType.valueOf(types));

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

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

相关文章