/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified RTSP version string. If the specified {@code text} is * equal to {@code "RTSP/1.0"}, {@link #RTSP_1_0} will be returned. * Otherwise, a new {@link HttpVersion} instance will be returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim().toUpperCase(); if ("RTSP/1.0".equals(text)) { return RTSP_1_0; } return new HttpVersion(text, true); }
/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified protocol version string. If the specified {@code text} is * equal to {@code "HTTP/1.0"}, {@link #HTTP_1_0} will be returned. If the * specified {@code text} is equal to {@code "HTTP/1.1"}, {@link #HTTP_1_1} * will be returned. Otherwise, a new {@link HttpVersion} instance will be * returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim(); if (text.isEmpty()) { throw new IllegalArgumentException("text is empty (possibly HTTP/0.9)"); } // Try to match without convert to uppercase first as this is what 99% of all clients // will send anyway. Also there is a change to the RFC to make it clear that it is // expected to be case-sensitive // // See: // * http://trac.tools.ietf.org/wg/httpbis/trac/ticket/1 // * http://trac.tools.ietf.org/wg/httpbis/trac/wiki // HttpVersion version = version0(text); if (version == null) { version = new HttpVersion(text, true); } return version; }
/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified RTSP version string. If the specified {@code text} is * equal to {@code "RTSP/1.0"}, {@link #RTSP_1_0} will be returned. * Otherwise, a new {@link HttpVersion} instance will be returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim().toUpperCase(); if ("RTSP/1.0".equals(text)) { return RTSP_1_0; } return new HttpVersion(text, true); }
/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified RTSP version string. If the specified {@code text} is * equal to {@code "RTSP/1.0"}, {@link #RTSP_1_0} will be returned. * Otherwise, a new {@link HttpVersion} instance will be returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim().toUpperCase(); if ("RTSP/1.0".equals(text)) { return RTSP_1_0; } return new HttpVersion(text, true); }
/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified RTSP version string. If the specified {@code text} is * equal to {@code "RTSP/1.0"}, {@link #RTSP_1_0} will be returned. * Otherwise, a new {@link HttpVersion} instance will be returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim().toUpperCase(); if ("RTSP/1.0".equals(text)) { return RTSP_1_0; } return new HttpVersion(text, true); }
/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified RTSP version string. If the specified {@code text} is * equal to {@code "RTSP/1.0"}, {@link #RTSP_1_0} will be returned. * Otherwise, a new {@link HttpVersion} instance will be returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim().toUpperCase(); if ("RTSP/1.0".equals(text)) { return RTSP_1_0; } return new HttpVersion(text, true); }
/** * Constructor to create a new {@code Http2PushPromise} with uri and http method. * * @param method the http method * @param uri the uri */ public Http2PushPromise(String method, String uri) { httpRequest = new DefaultHttpRequest(new HttpVersion(Constants.HTTP_VERSION_2_0, true), HttpMethod.valueOf(method), uri); }
private static HttpVersion getHttpVersion(HttpCarbonMessage outboundRequestMsg) { HttpVersion httpVersion; if (null != outboundRequestMsg.getProperty(Constants.HTTP_VERSION)) { httpVersion = new HttpVersion(Constants.HTTP_VERSION_PREFIX + outboundRequestMsg.getProperty(Constants.HTTP_VERSION), true); } else { httpVersion = new HttpVersion(Constants.DEFAULT_VERSION_HTTP_1_1, true); } return httpVersion; }
private void sendSDFileContent( DefaultHttpServerConnection serverConnection, RequestLine requestLine) throws IOException, HttpException { HttpResponse response = new BasicHttpResponse(new HttpVersion(1, 1), 200, "OK"); String SDfileId = getSDFileId(requestLine.getUri()); Log.d("selected URI from server", SDfileId); addSDFileEntity(Uri.withAppendedPath( NewSDCardContentProvider.SDFiles.CONTENT_URI, SDfileId), response); serverConnection.sendResponseHeader(response); serverConnection.sendResponseEntity(response); }
public static HttpResponse createFullHttpResponse(HttpCarbonMessage outboundResponseMsg, String inboundReqHttpVersion, String serverName, boolean keepAlive, ByteBuf fullContent) { HttpVersion httpVersion = new HttpVersion(Constants.HTTP_VERSION_PREFIX + inboundReqHttpVersion, true); HttpResponseStatus httpResponseStatus = getHttpResponseStatus(outboundResponseMsg); HttpResponse outboundNettyResponse = new DefaultFullHttpResponse(httpVersion, httpResponseStatus, fullContent, false); setOutboundRespHeaders(outboundResponseMsg, inboundReqHttpVersion, serverName, keepAlive, outboundNettyResponse); return outboundNettyResponse; }
/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified protocol version string. If the specified {@code text} is * equal to {@code "HTTP/1.0"}, {@link #HTTP_1_0} will be returned. If the * specified {@code text} is equal to {@code "HTTP/1.1"}, {@link #HTTP_1_1} * will be returned. Otherwise, a new {@link HttpVersion} instance will be * returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim(); if (text.isEmpty()) { throw new IllegalArgumentException("text is empty (possibly HTTP/0.9)"); } // Try to match without convert to uppercase first as this is what 99% of all clients // will send anyway. Also there is a change to the RFC to make it clear that it is // expected to be case-sensitive // // See: // * http://trac.tools.ietf.org/wg/httpbis/trac/ticket/1 // * http://trac.tools.ietf.org/wg/httpbis/trac/wiki // HttpVersion version = version0(text); if (version == null) { version = new HttpVersion(text, true); } return version; }
/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified protocol version string. If the specified {@code text} is * equal to {@code "HTTP/1.0"}, {@link #HTTP_1_0} will be returned. If the * specified {@code text} is equal to {@code "HTTP/1.1"}, {@link #HTTP_1_1} * will be returned. Otherwise, a new {@link HttpVersion} instance will be * returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim(); if (text.isEmpty()) { throw new IllegalArgumentException("text is empty (possibly HTTP/0.9)"); } // Try to match without convert to uppercase first as this is what 99% of all clients // will send anyway. Also there is a change to the RFC to make it clear that it is // expected to be case-sensitive // // See: // * http://trac.tools.ietf.org/wg/httpbis/trac/ticket/1 // * http://trac.tools.ietf.org/wg/httpbis/trac/wiki // HttpVersion version = version0(text); if (version == null) { version = new HttpVersion(text, true); } return version; }
/** * Returns an existing or new {@link HttpVersion} instance which matches to * the specified protocol version string. If the specified {@code text} is * equal to {@code "HTTP/1.0"}, {@link #HTTP_1_0} will be returned. If the * specified {@code text} is equal to {@code "HTTP/1.1"}, {@link #HTTP_1_1} * will be returned. Otherwise, a new {@link HttpVersion} instance will be * returned. */ public static HttpVersion valueOf(String text) { if (text == null) { throw new NullPointerException("text"); } text = text.trim(); if (text.isEmpty()) { throw new IllegalArgumentException("text is empty (possibly HTTP/0.9)"); } // Try to match without convert to uppercase first as this is what 99% of all clients // will send anyway. Also there is a change to the RFC to make it clear that it is // expected to be case-sensitive // // See: // * http://trac.tools.ietf.org/wg/httpbis/trac/ticket/1 // * http://trac.tools.ietf.org/wg/httpbis/trac/wiki // HttpVersion version = version0(text); if (version == null) { version = new HttpVersion(text, true); } return version; }
@SuppressWarnings("unchecked") public static HttpResponse createHttpResponse(HttpCarbonMessage outboundResponseMsg, String inboundReqHttpVersion, String serverName, boolean keepAlive) { HttpVersion httpVersion = new HttpVersion(Constants.HTTP_VERSION_PREFIX + inboundReqHttpVersion, true); HttpResponseStatus httpResponseStatus = getHttpResponseStatus(outboundResponseMsg); HttpResponse outboundNettyResponse = new DefaultHttpResponse(httpVersion, httpResponseStatus, false); setOutboundRespHeaders(outboundResponseMsg, inboundReqHttpVersion, serverName, keepAlive, outboundNettyResponse); return outboundNettyResponse; }
private void readTrailerHeaders(int streamId, Http2Headers headers, HttpCarbonMessage responseMessage) throws Http2Exception { HttpVersion version = new HttpVersion(HTTP_VERSION_2_0, true); LastHttpContent lastHttpContent = new DefaultLastHttpContent(); HttpHeaders trailers = lastHttpContent.trailingHeaders(); HttpConversionUtil.addHttp2ToHttpHeaders(streamId, headers, trailers, version, true, false); responseMessage.addHttpContent(lastHttpContent); }
private void onTrailersRead(int streamId, Http2Headers headers, OutboundMsgHolder outboundMsgHolder, HttpCarbonMessage responseMessage) { HttpVersion version = new HttpVersion(HTTP_VERSION_2_0, true); LastHttpContent lastHttpContent = new DefaultLastHttpContent(); HttpHeaders trailers = lastHttpContent.trailingHeaders(); try { HttpConversionUtil.addHttp2ToHttpHeaders(streamId, headers, trailers, version, true, false); } catch (Http2Exception e) { outboundMsgHolder.getResponseFuture(). notifyHttpListener(new Exception("Error while setting http headers", e)); } responseMessage.addHttpContent(lastHttpContent); }
/** * Creates a {@link HttpRequest} using a {@link Http2Headers} received over a particular HTTP/2 stream. * * @param http2Headers the Http2Headers received over a HTTP/2 stream * @param streamId the stream id * @return the HttpRequest formed using the HttpHeaders * @throws Http2Exception if an error occurs while converting headers from HTTP/2 to HTTP */ public static HttpRequest createHttpRequestFromHttp2Headers(Http2Headers http2Headers, int streamId) throws Http2Exception { String method = Constants.HTTP_GET_METHOD; if (http2Headers.method() != null) { method = http2Headers.getAndRemove(Constants.HTTP2_METHOD).toString(); } String path = Constants.DEFAULT_BASE_PATH; if (http2Headers.path() != null) { path = http2Headers.getAndRemove(Constants.HTTP2_PATH).toString(); } // Remove PseudoHeaderNames from headers http2Headers.getAndRemove(Constants.HTTP2_AUTHORITY); http2Headers.getAndRemove(Constants.HTTP2_SCHEME); HttpVersion version = new HttpVersion(Constants.HTTP_VERSION_2_0, true); // Construct new HTTP Carbon Request HttpRequest httpRequest = new DefaultHttpRequest(version, HttpMethod.valueOf(method), path); // Convert Http2Headers to HttpHeaders HttpConversionUtil.addHttp2ToHttpHeaders( streamId, http2Headers, httpRequest.headers(), version, false, true); return httpRequest; }
/** * Handles the cleartext HTTP upgrade event. * <p> * If an upgrade occurred, message needs to be dispatched to * the correct service/resource and response should be delivered over stream 1 * (the stream specifically reserved for cleartext HTTP upgrade). */ @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) { FullHttpRequest upgradedRequest = ((HttpServerUpgradeHandler.UpgradeEvent) evt).upgradeRequest(); // Construct new HTTP Request HttpRequest httpRequest = new DefaultHttpRequest( new HttpVersion(Constants.HTTP_VERSION_2_0, true), upgradedRequest.method(), upgradedRequest.uri(), upgradedRequest.headers()); HttpCarbonRequest requestCarbonMessage = setupCarbonRequest(httpRequest, ctx, interfaceId); requestCarbonMessage.addHttpContent(new DefaultLastHttpContent(upgradedRequest.content())); notifyRequestListener(this, requestCarbonMessage, 1); } }
@SuppressWarnings("unchecked") public static HttpRequest createHttpRequest(HTTPCarbonMessage msg) { HttpMethod httpMethod; if (null != msg.getProperty(Constants.HTTP_METHOD)) { httpMethod = new HttpMethod((String) msg.getProperty(Constants.HTTP_METHOD)); } else { httpMethod = new HttpMethod(DEFAULT_HTTP_METHOD_POST); } HttpVersion httpVersion; if (null != msg.getProperty(Constants.HTTP_VERSION)) { httpVersion = new HttpVersion((String) msg.getProperty(Constants.HTTP_VERSION), true); } else { httpVersion = new HttpVersion(DEFAULT_VERSION_HTTP_1_1, true); } if ((String) msg.getProperty(Constants.TO) == null) { msg.setProperty(Constants.TO, "/"); } HttpRequest outgoingRequest = new DefaultHttpRequest(httpVersion, httpMethod, (String) msg.getProperty(Constants.TO), false); HttpHeaders headers = msg.getHeaders(); outgoingRequest.headers().setAll(headers); return outgoingRequest; }
@SuppressWarnings("unchecked") public static HttpResponse createHttpResponse(HTTPCarbonMessage msg, boolean connectionCloseAfterResponse) { HttpVersion httpVersion = new HttpVersion(Util.getStringValue(msg, Constants.HTTP_VERSION, HTTP_1_1.text()), true); int statusCode = Util.getIntValue(msg, Constants.HTTP_STATUS_CODE, 200); String reasonPhrase = Util.getStringValue(msg, Constants.HTTP_REASON_PHRASE, HttpResponseStatus.valueOf(statusCode).reasonPhrase()); HttpResponseStatus httpResponseStatus = new HttpResponseStatus(statusCode, reasonPhrase); DefaultHttpResponse outgoingResponse = new DefaultHttpResponse(httpVersion, httpResponseStatus, false); if (connectionCloseAfterResponse) { msg.setHeader(Constants.HTTP_CONNECTION, Constants.CONNECTION_CLOSE); } outgoingResponse.headers().setAll(msg.getHeaders()); return outgoingResponse; }