requestPacket.setContentType("application/x-www-form-urlencoded"); String charset = request.getBodyEncoding(); if (charset == null) { charset = Charsets.ASCII_CHARSET.name();
urlConnection.setRequestProperty("Content-Length", "0"); urlConnection.setDoOutput(true); String bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET.name() : request.getBodyEncoding();
@Override public String getBodyEncoding() { return delegate.getBodyEncoding(); }
@SuppressWarnings({"unchecked"}) public boolean generate(final FilterChainContext ctx, final Request request, final HttpRequestPacket requestPacket) throws IOException { String charset = request.getBodyEncoding(); if (charset == null) { charset = Charsets.ASCII_CHARSET.name(); } final byte[] data = request.getStringData().getBytes(charset); final MemoryManager mm = ctx.getMemoryManager(); final Buffer gBuffer = Buffers.wrap(mm, data); if (requestPacket.getContentLength() == -1) { requestPacket.setContentLengthLong(data.length); } final HttpContent content = requestPacket.httpContentBuilder() .content(gBuffer) .last(true) .build(); ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null)); return true; }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }
if (!connect) { Charset bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET : Charset.forName(request.getBodyEncoding());
requestBuilder.setBodyEncoding(request.getBodyEncoding()); if (MiscUtils.isNonEmpty(request.getFormParams())) requestBuilder.setFormParams(request.getFormParams());
@Test(groups = {"standalone", "default_provider"}) public void testContentTypeCharsetToBodyEncoding() { final Request req = new RequestBuilder("GET").setHeader("Content-Type", "application/json; charset=XXXX").build(); assertEquals(req.getBodyEncoding(), "XXXX"); final Request req2 = new RequestBuilder("GET").setHeader("Content-Type", "application/json; charset=\"XXXX\"").build(); assertEquals(req2.getBodyEncoding(), "XXXX"); }
requestPacket.setContentType("application/x-www-form-urlencoded"); String charset = request.getBodyEncoding(); if (charset == null) { charset = Charsets.ASCII_CHARSET.name();
requestPacket.setContentType("application/x-www-form-urlencoded"); String charset = request.getBodyEncoding(); if (charset == null) { charset = Charsets.ASCII_CHARSET.name();
requestPacket.setContentType("application/x-www-form-urlencoded"); String charset = request.getBodyEncoding(); if (charset == null) { charset = Charsets.ASCII_CHARSET.name();
urlConnection.setRequestProperty("Content-Length", "0"); urlConnection.setDoOutput(true); String bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET.name() : request.getBodyEncoding();
@SuppressWarnings({"unchecked"}) public boolean generate(final FilterChainContext ctx, final Request request, final HttpRequestPacket requestPacket) throws IOException { String charset = request.getBodyEncoding(); if (charset == null) { charset = Charsets.ASCII_CHARSET.name(); } final byte[] data = request.getStringData().getBytes(charset); final MemoryManager mm = ctx.getMemoryManager(); final Buffer gBuffer = Buffers.wrap(mm, data); if (requestPacket.getContentLength() == -1) { requestPacket.setContentLengthLong(data.length); } final HttpContent content = requestPacket.httpContentBuilder() .content(gBuffer) .last(true) .build(); ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null)); return true; }
@SuppressWarnings({"unchecked"}) public boolean generate(final FilterChainContext ctx, final Request request, final HttpRequestPacket requestPacket) throws IOException { String charset = request.getBodyEncoding(); if (charset == null) { charset = Charsets.ASCII_CHARSET.name(); } final byte[] data = request.getStringData().getBytes(charset); final MemoryManager mm = ctx.getMemoryManager(); final Buffer gBuffer = Buffers.wrap(mm, data); if (requestPacket.getContentLength() == -1) { requestPacket.setContentLengthLong(data.length); } final HttpContent content = requestPacket.httpContentBuilder() .content(gBuffer) .last(true) .build(); ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null)); return true; }
@SuppressWarnings({"unchecked"}) public boolean doHandle(final FilterChainContext ctx, final Request request, final HttpRequestPacket requestPacket) throws IOException { String charset = request.getBodyEncoding(); if (charset == null) { charset = Charsets.ASCII_CHARSET.name(); } final byte[] data = request.getStringData().getBytes(charset); final MemoryManager mm = ctx.getMemoryManager(); final Buffer gBuffer = Buffers.wrap(mm, data); if (requestPacket.getContentLength() == -1) { if (!clientConfig.isCompressionEnabled()) { requestPacket.setContentLengthLong(data.length); } } final HttpContent content = requestPacket.httpContentBuilder().content(gBuffer).build(); content.setLast(true); ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null)); return true; }
EntityEnclosingMethod post = methodName.equalsIgnoreCase("POST") ? new PostMethod(request.getURI().toUrl()) : new PutMethod(request.getURI().toUrl()); String bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET.name() : request.getBodyEncoding();
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getURI(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<Cookie>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<Param>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<Part>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolKeyStrategy = prototype.getConnectionPoolKeyStrategy(); } }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }
private NettyBody body(Request request, HttpMethod method) throws IOException { NettyBody nettyBody = null; if (method != HttpMethod.CONNECT) { Charset bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET : Charset.forName(request.getBodyEncoding()); if (request.getByteData() != null) nettyBody = new NettyByteArrayBody(request.getByteData()); else if (request.getStringData() != null) nettyBody = new NettyByteArrayBody(request.getStringData().getBytes(bodyCharset)); else if (request.getStreamData() != null) nettyBody = new NettyInputStreamBody(request.getStreamData()); else if (isNonEmpty(request.getFormParams())) { String contentType = null; if (!request.getHeaders().containsKey(HttpHeaders.Names.CONTENT_TYPE)) contentType = HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED; nettyBody = new NettyByteArrayBody(computeBodyFromParams(request.getFormParams(), bodyCharset), contentType); } else if (isNonEmpty(request.getParts())) nettyBody = new NettyMultipartBody(request.getParts(), request.getHeaders(), nettyConfig); else if (request.getFile() != null) nettyBody = new NettyFileBody(request.getFile(), nettyConfig); else if (request.getBodyGenerator() instanceof FileBodyGenerator) { FileBodyGenerator fileBodyGenerator = (FileBodyGenerator) request.getBodyGenerator(); nettyBody = new NettyFileBody(fileBodyGenerator.getFile(), fileBodyGenerator.getRegionSeek(), fileBodyGenerator.getRegionLength(), nettyConfig); } else if (request.getBodyGenerator() instanceof InputStreamBodyGenerator) nettyBody = new NettyInputStreamBody(InputStreamBodyGenerator.class.cast(request.getBodyGenerator()).getInputStream()); else if (request.getBodyGenerator() != null) nettyBody = new NettyBodyBody(request.getBodyGenerator().createBody(), nettyConfig); } return nettyBody; }