当前位置: 首页>>代码示例>>Java>>正文


Java Request.getHeader方法代码示例

本文整理汇总了Java中org.eclipse.jetty.server.Request.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java Request.getHeader方法的具体用法?Java Request.getHeader怎么用?Java Request.getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.server.Request的用法示例。


在下文中一共展示了Request.getHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeResponse

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
private void writeResponse(Request baseRequest, HttpServletResponse response, Object data) throws IOException{
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/json; charset=utf-8");

    String origin = baseRequest.getHeader("Origin");
    if(origin != null) {
        response.setHeader("Access-Control-Allow-Origin", origin);
    }

    PrintWriter out = response.getWriter();
    out.println(jparser.toJson(data));
    baseRequest.setHandled(true);
}
 
开发者ID:nemec,项目名称:JDHttpAPI,代码行数:14,代码来源:BaseHandler.java

示例2: setUp

import org.eclipse.jetty.server.Request; //导入方法依赖的package包/类
/**
 * Set up server with handler
 *
 * @param handler
 * @return port
 * @throws Exception
 */
public static String setUp(final Handler handler) throws Exception {
  server = new Server();
  if (handler != null)
    server.setHandler(handler);
  Connector connector = new SelectChannelConnector();
  connector.setPort(0);
  server.setConnectors(new Connector[] { connector });
  server.start();

  proxy = new Server();
  Connector proxyConnector = new SelectChannelConnector();
  proxyConnector.setPort(0);
  proxy.setConnectors(new Connector[] { proxyConnector });

  ServletHandler proxyHandler = new ServletHandler();

  RequestHandler proxyCountingHandler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      proxyHitCount.incrementAndGet();
      String auth = request.getHeader("Proxy-Authorization");
      auth = auth.substring(auth.indexOf(' ') + 1);
      try {
        auth = B64Code.decode(auth, CHARSET_UTF8);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
      int colon = auth.indexOf(':');
      proxyUser.set(auth.substring(0, colon));
      proxyPassword.set(auth.substring(colon + 1));
      request.setHandled(false);
    }
  };

  HandlerList handlerList = new HandlerList();
  handlerList.addHandler(proxyCountingHandler);
  handlerList.addHandler(proxyHandler);
  proxy.setHandler(handlerList);

  ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
  proxyHolder.setAsyncSupported(true);

  proxy.start();

  proxyPort = proxyConnector.getLocalPort();

  return "http://localhost:" + connector.getLocalPort();
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:57,代码来源:ServerTestCase.java


注:本文中的org.eclipse.jetty.server.Request.getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。