當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。