ro.pippo.core.Response.header()方法的使用及代码示例

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

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

Response.header介绍

[英]Sets a header.
[中]设置标题。

代码示例

代码示例来源:origin: pippo-java/pippo

@Override
public Date setHeader(String name, Date date) {
  response.header(name, date);
  return date;
}

代码示例来源:origin: pippo-java/pippo

/**
 * Sets a filename header. It's a shortcut for {@code header(HttpConstants.Header.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")}.
 *
 * @param filename
 * @return
 */
public Response filenameHeader(String filename) {
  if (filename != null && !filename.isEmpty()) {
    header(HttpConstants.Header.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"");
  } else {
    header(HttpConstants.Header.CONTENT_DISPOSITION, "attachment; filename=\"\"");
  }
  return this;
}

代码示例来源:origin: pippo-java/pippo

@Override
public <T> T setHeader(String name, T value) {
  response.header(name, value.toString());
  return value;
}

代码示例来源:origin: pippo-java/pippo

/**
 * Sets this response as not cacheable.
 *
 * @return the response
 */
public Response noCache() {
  checkCommitted();
  // no-cache headers for HTTP/1.1
  header(HttpConstants.Header.CACHE_CONTROL, "no-store, no-cache, must-revalidate");
  // no-cache headers for HTTP/1.1 (IE)
  header(HttpConstants.Header.CACHE_CONTROL, "post-check=0, pre-check=0");
  // no-cache headers for HTTP/1.0
  header(HttpConstants.Header.PRAGMA, "no-cache");
  // set the expires to past
  httpServletResponse.setDateHeader("Expires", 0);
  return this;
}

代码示例来源:origin: pippo-java/pippo

/**
 * Sets the content type of the response.
 *
 * @param contentType
 * @return the response
 */
public Response contentType(String contentType) {
  checkCommitted();
  header(HttpConstants.Header.CONTENT_TYPE, contentType);
  httpServletResponse.setContentType(contentType);
  return this;
}

代码示例来源:origin: pippo-java/pippo

@Override
public void setResponseHeader(String name, String value) {
  getResponse().header(name, value);
}

代码示例来源:origin: pippo-java/pippo

@Override
public void handle(RouteContext context) {
  final Response response = context.getResponse();
  response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin);
  if (exposeHeaders != null) {
    response.header(HttpConstants.Header.ACCESS_CONTROL_EXPOSE_HEADERS, exposeHeaders);
  }
  if (maxAge != -1) {
    response.header(HttpConstants.Header.ACCESS_CONTROL_MAX_AGE, "" + maxAge);
  }
  // According to the documentation only if true is what needs to be set
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials#Directives
  if (allowCredentials) {
    response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
  }
  if (allowMethods != null) {
    response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_METHODS, allowMethods);
  }
  if (allowHeaders != null) {
    response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders);
  }
  if (context.getRequestMethod().equals("OPTIONS")) {
    response.accepted();
    return;
  }
  context.next();
}

代码示例来源:origin: pippo-java/pippo

/**
 * A permanent (3XX status code) redirect.
 * <p>This method commits the response.</p>
 *
 * @param location
 * @param statusCode
 */
public void redirect(String location, int statusCode) {
  checkCommitted();
  finalizeResponse();
  status(statusCode);
  header(HttpConstants.Header.LOCATION, location);
  header(HttpConstants.Header.CONNECTION, "close");
  try {
    httpServletResponse.sendError(statusCode);
  } catch (IOException e) {
    throw new PippoRuntimeException(e);
  }
}

代码示例来源:origin: pippo-java/pippo

private void send(Object object, String contentType) {
  if (StringUtils.isNullOrEmpty(contentType)) {
    throw new PippoRuntimeException("You must specify a content type!");
  }
  ContentTypeEngine contentTypeEngine = contentTypeEngines.getContentTypeEngine(contentType);
  if (contentTypeEngine == null) {
    throw new PippoRuntimeException("You must set a content type engine for '{}'", contentType);
  }
  header(HttpConstants.Header.CONTENT_TYPE, contentTypeEngine.getContentType());
  send(contentTypeEngine.toString(object));
}

代码示例来源:origin: pippo-java/pippo

response.badRequest().header("Sec-WebSocket-Version", "13"); // http://tools.ietf.org/html/rfc6455#section-4.4
return false;
response.header("Sec-WebSocket-Protocol", subProtocol);

代码示例来源:origin: com.gitblit.fathom/fathom-rest

@Override
  protected void writeObject(Context context, Object result) {
    try {
      context.getResponse()
        .contentType(CONTENT_TYPE)
        .header(CLASS_NAME, result == null ? NULL : result.getClass().getName());

      if (result != null) {
        GZIPOutputStream zipStream = new GZIPOutputStream(new BufferedOutputStream(context.getResponse().getOutputStream()));
        ObjectOutputStream replyStream = new ObjectOutputStream(zipStream);
        replyStream.writeObject(result);
        zipStream.finish();
        replyStream.flush();
      }
    } catch (IOException e) {
    }
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-rest

protected void writeObject(Context context, Object result) {
    try {
      context.getResponse()
        .contentType(CONTENT_TYPE)
        .header(CLASS_NAME, result == null ? NULL : result.getClass().getName());

      if (result != null) {
        ObjectOutputStream replyStream = new ObjectOutputStream(context.getResponse().getOutputStream());
        replyStream.writeObject(result);
        replyStream.flush();
      }
    } catch (IOException e) {
    }
  }
}

代码示例来源:origin: gitblit/fathom

@Override
  protected void writeObject(Context context, Object result) {
    try {
      context.getResponse()
        .contentType(CONTENT_TYPE)
        .header(CLASS_NAME, result == null ? NULL : result.getClass().getName());

      if (result != null) {
        GZIPOutputStream zipStream = new GZIPOutputStream(new BufferedOutputStream(context.getResponse().getOutputStream()));
        ObjectOutputStream replyStream = new ObjectOutputStream(zipStream);
        replyStream.writeObject(result);
        zipStream.finish();
        replyStream.flush();
      }
    } catch (IOException e) {
    }
  }
}

代码示例来源:origin: gitblit/fathom

protected void writeObject(Context context, Object result) {
    try {
      context.getResponse()
        .contentType(CONTENT_TYPE)
        .header(CLASS_NAME, result == null ? NULL : result.getClass().getName());

      if (result != null) {
        ObjectOutputStream replyStream = new ObjectOutputStream(context.getResponse().getOutputStream());
        replyStream.writeObject(result);
        replyStream.flush();
      }
    } catch (IOException e) {
    }
  }
}

相关文章