本文整理匯總了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);
}
示例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();
}