当前位置: 首页>>代码示例>>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;未经允许,请勿转载。