當前位置: 首頁>>代碼示例>>Java>>正文


Java FullHttpRequest.getMethod方法代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.FullHttpRequest.getMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java FullHttpRequest.getMethod方法的具體用法?Java FullHttpRequest.getMethod怎麽用?Java FullHttpRequest.getMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.codec.http.FullHttpRequest的用法示例。


在下文中一共展示了FullHttpRequest.getMethod方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleHttpRequest

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) {
	// Handle a bad request.
	if (!req.getDecoderResult().isSuccess()) {
		logger.warn(String.format("Bad request: %s", req.getUri()));
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
		return;
	}

	// Allow only GET methods.
	if (req.getMethod() != GET) {
		logger.warn(String.format("Unsupported HTTP method: %s", req.getMethod()));
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
		return;
	}

	// enable subclasses to do additional processing
	if (!additionalHttpRequestHandler(ctx, req)) {
		return;
	}

	// Handshake
	WebSocketServerHandshakerFactory wsFactory
		= new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, true);

	handshaker = wsFactory.newHandshaker(req);
	if (handshaker == null) {
		WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
	} else {
		handshaker.handshake(ctx.channel(), req);
		WebsocketSinkServer.channels.add(ctx.channel());
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:33,代碼來源:WebsocketSinkServerHandler.java

示例2: handleHttpRequest

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
protected void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
    // Handle a bad request.
    if (!req.getDecoderResult().isSuccess()) {
        httpFileHandler.sendError(ctx, HttpResponseStatus.BAD_REQUEST);
        return;
    }

    // If you're going to do normal HTTP POST authentication before upgrading the
    // WebSocket, the recommendation is to handle it right here
    if (req.getMethod() == HttpMethod.POST) {
        httpFileHandler.sendError(ctx, HttpResponseStatus.FORBIDDEN);
        return;
    }

    // Allow only GET methods.
    if (req.getMethod() != HttpMethod.GET) {
        httpFileHandler.sendError(ctx, HttpResponseStatus.FORBIDDEN);
        return;
    }

    // Send the demo page and favicon.ico
    if ("/".equals(req.getUri())) {
        httpFileHandler.sendRedirect(ctx, "/index.html");
        return;
    }

    // check for websocket upgrade request
    String upgradeHeader = req.headers().get("Upgrade");
    if (upgradeHeader != null && "websocket".equalsIgnoreCase(upgradeHeader)) {
        // Handshake. Ideally you'd want to configure your websocket uri
        String url = "ws://" + req.headers().get("Host") + "/marketdata";
        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(url, null, false);
        handshaker = wsFactory.newHandshaker(req);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        }
        else {
            handshaker.handshake(ctx.channel(), req);
        }
    }
    else {
        boolean handled = handleREST(ctx, req);
        if (!handled) {
            httpFileHandler.sendFile(ctx, req);
        }
    }
}
 
開發者ID:SpreadServe,項目名稱:TFWebSock,代碼行數:48,代碼來源:WebSocketHandler.java

示例3: getRequestHash

import io.netty.handler.codec.http.FullHttpRequest; //導入方法依賴的package包/類
private String getRequestHash(FullHttpRequest request) {
	HttpHeaders headers = request.headers();
	String requestURI = getRequestURI(request);
	HttpMethod requestMethod = request.getMethod();
	Set<String> skipHeaders = m_skipHeaders;
	boolean skipRequestContent = m_uriMatchEnabled
			&& WildcardMatcher.isPatternCanBeMatchedIn(
					m_uriMatchOnly,
					new CacheDecisionObject(requestURI, requestMethod
							.name()));
	if(skipRequestContent){
		skipHeaders = new HashSet<>(m_skipHeaders);
		skipHeaders.add(HttpHeaders.Names.CONTENT_LENGTH.toUpperCase());
	}

	int uriHashcode = requestURI.hashCode();
	int methodHashCode = requestMethod.hashCode();
	List<Entry<String, String>> entries = headers.entries();
	List<String> hashList = new ArrayList<>();
	for (Iterator<Entry<String, String>> it = entries.iterator(); it
			.hasNext();) {
		Entry<String, String> entry = it.next();
		if (skipHeaders.contains(entry.getKey().toUpperCase())) {
			continue;
		}
		hashList.add(entry.getKey());
		hashList.add(entry.getValue());
	}

	int headersHashcode = hashList.hashCode();

	StringBuilder sb = new StringBuilder(4);
	sb.append(uriHashcode).append(methodHashCode).append(headersHashcode);

	if (!skipRequestContent) {
		ByteBuf content = request.content();
		sb.append(content.hashCode());
	}

	return Checksum.checksum(sb.toString());
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:42,代碼來源:RequestKeyGenerator.java


注:本文中的io.netty.handler.codec.http.FullHttpRequest.getMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。