List of usage examples for io.netty.handler.codec.http DefaultHttpRequest DefaultHttpRequest
public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, HttpHeaders headers)
From source file:com.creamsugardonut.CustomHttpRequestDecoder.java
License:Apache License
@Override protected HttpMessage createMessage(String[] initialLine) throws Exception { return new DefaultHttpRequest(HttpVersion.valueOf(initialLine[2]), HttpMethod.valueOf(initialLine[0]), initialLine[1], validateHeaders); }
From source file:com.github.ambry.rest.NettyRequestTest.java
License:Open Source License
/** * Creates a {@link NettyRequest} with the given parameters. * @param httpMethod the {@link HttpMethod} desired. * @param uri the URI desired.//from w w w. ja va 2 s .com * @param headers {@link HttpHeaders} that need to be a part of the request. * @return {@link NettyRequest} encapsulating a {@link HttpRequest} with the given parameters. * @throws RestServiceException if the {@code httpMethod} is not recognized by {@link NettyRequest}. */ private NettyRequest createNettyRequest(HttpMethod httpMethod, String uri, HttpHeaders headers) throws RestServiceException { MetricRegistry metricRegistry = new MetricRegistry(); RestRequestMetricsTracker.setDefaults(metricRegistry); HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, httpMethod, uri, false); if (headers != null) { httpRequest.headers().set(headers); } return new NettyRequest(httpRequest, new NettyMetrics(metricRegistry)); }
From source file:com.linecorp.armeria.internal.http.Http1ObjectEncoder.java
License:Apache License
private HttpObject convertClientHeaders(int streamId, HttpHeaders headers) throws Http2Exception { // Leading headers will always have :method, trailers will never have it. final HttpMethod method = headers.method(); if (method == null) { return convertTrailingHeaders(streamId, headers); }//from w w w. j a va 2 s.co m // Convert leading headers. final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method.toNettyMethod(), headers.path(), false); convert(streamId, headers, req.headers(), false); if (HttpUtil.getContentLength(req, -1L) >= 0) { // Avoid the case where both 'content-length' and 'transfer-encoding' are set. req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING); } else { req.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); } return req; }
From source file:com.linecorp.armeria.internal.Http1ObjectEncoder.java
License:Apache License
private HttpObject convertClientHeaders(int streamId, HttpHeaders headers, boolean endStream) throws Http2Exception { // Leading headers will always have :method, trailers will never have it. final HttpMethod method = headers.method(); if (method == null) { return convertTrailingHeaders(streamId, headers); }/*w w w.ja v a 2s . c om*/ // Convert leading headers. final String path = headers.path(); assert path != null; final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, io.netty.handler.codec.http.HttpMethod.valueOf(method.name()), path, false); convert(streamId, headers, req.headers(), false); if (endStream) { req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING); req.headers().remove(HttpHeaderNames.CONTENT_LENGTH); } else if (HttpUtil.getContentLength(req, -1L) >= 0) { // Avoid the case where both 'content-length' and 'transfer-encoding' are set. req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING); } else { req.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); } return req; }
From source file:com.sengled.cloud.mediaserver.rtsp.codec.RtspRequestDecoder.java
License:Apache License
@Override protected HttpMessage createMessage(String[] initialLine) throws Exception { return new DefaultHttpRequest(RtspVersions.valueOf(initialLine[2]), RtspMethods.valueOf(initialLine[0]), initialLine[1], validateHeaders); }
From source file:io.advantageous.conekt.http.impl.HttpClientRequestImpl.java
License:Open Source License
HttpClientRequestImpl(HttpClientImpl client, io.advantageous.conekt.http.HttpMethod method, String host,
int port, String relativeURI, ConektInternal vertx) {
this.host = host;
this.port = port;
this.client = client;
this.request = new DefaultHttpRequest(toNettyHttpVersion(client.getOptions().getProtocolVersion()),
toNettyHttpMethod(method), relativeURI, false);
this.chunked = false;
this.method = method;
this.vertx = vertx;
}
From source file:io.gatling.http.client.impl.request.WritableRequestBuilder.java
License:Apache License
private static WritableRequest buildRequestWithBody(String url, Uri uri, HttpMethod method, HttpHeaders headers, RequestBody<?> requestBody, ByteBufAllocator alloc, HttpClientConfig config) throws IOException { boolean zeroCopy = !uri.isSecured() && config.isEnableZeroCopy(); WritableContent writableContent = requestBody.build(zeroCopy, alloc); Object content = writableContent.getContent(); if (content instanceof ByteBuf) { ByteBuf bb = (ByteBuf) content;/*from w ww. j a v a2 s. c o m*/ if (!headers.contains(CONTENT_LENGTH)) { headers.set(CONTENT_LENGTH, bb.readableBytes()); } FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, url, bb, headers, EmptyHttpHeaders.INSTANCE); return new WritableRequest(nettyRequest, null); } else { if (!headers.contains(CONTENT_LENGTH) && !headers.contains(TRANSFER_ENCODING)) { if (writableContent.getContentLength() >= 0) { headers.set(CONTENT_LENGTH, writableContent.getContentLength()); } else { headers.set(TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); } } HttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, url, headers); return new WritableRequest(nettyRequest, content); } }
From source file:io.jsync.http.impl.DefaultHttpClientRequest.java
License:Open Source License
private DefaultHttpClientRequest(final DefaultHttpClient client, final String method, final String uri, final Handler<HttpClientResponse> respHandler, final DefaultContext context, final boolean raw) { this.client = client; this.request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method), uri, false); this.chunked = false; this.respHandler = respHandler; this.context = context; this.raw = raw; }
From source file:io.vertx.core.http.impl.ClientConnection.java
License:Open Source License
private HttpRequest createRequest(HttpVersion version, HttpMethod method, String rawMethod, String uri, MultiMap headers) {/*ww w. j ava 2s. c o m*/ DefaultHttpRequest request = new DefaultHttpRequest(HttpUtils.toNettyHttpVersion(version), HttpUtils.toNettyHttpMethod(method, rawMethod), uri, false); if (headers != null) { for (Map.Entry<String, String> header : headers) { // Todo : multi valued headers request.headers().add(header.getKey(), header.getValue()); } } return request; }
From source file:io.vertx.core.http.impl.VertxHttpRequestDecoder.java
License:Open Source License
@Override protected HttpMessage createMessage(String[] initialLine) { return new DefaultHttpRequest(HttpVersion.valueOf(initialLine[2]), HttpMethod.valueOf(initialLine[0]), initialLine[1], new VertxHttpHeaders()); }