/** * @see FluentCaseInsensitiveStringsMap#getFirstValue(String) */ public String getFirstValue(String key) { return headers.getFirstValue(key); }
/** * Set headers to this listener. * * @param headers * {@link FluentCaseInsensitiveStringsMap} */ public void headers(FluentCaseInsensitiveStringsMap headers) { this.headers = headers; // Netty 3 bug hack: last chunk is not notified, fixed in Netty 4 String contentLength = headers.getFirstValue("Content-Length"); if (contentLength != null) expectedTotal = Long.valueOf(contentLength); }
private void computeRequestLength() { if (request.length < 0 && request.streamData == null) { // can't concatenate content-length final String contentLength = request.headers.getFirstValue("Content-Length"); if (contentLength != null) { try { request.length = Long.parseLong(contentLength); } catch (NumberFormatException e) { // NoOp -- we wdn't specify length so it will be chunked? } } } }
@Override public final String getHeader(String name) { return headers != null ? getHeaders().getFirstValue(name) : null; }
private void calculateTotal(HttpResponseHeaders headers) { String length = headers.getHeaders().getFirstValue("Content-Length"); try { total = Integer.valueOf(length); } catch (Exception e) { total = -1; } }
private void computeRequestCharset() { if (request.charset == null) { try { final String contentType = request.headers.getFirstValue("Content-Type"); if (contentType != null) { final String charset = AsyncHttpProviderUtils.parseCharset(contentType); if (charset != null) { // ensure that if charset is provided with the Content-Type header, // we propagate that down to the charset of the Request object request.charset = charset; } } } catch (Throwable e) { // NoOp -- we can't fix the Content-Type or charset from here } } }
@Override public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { responseBuilder.accumulate(headers); String contentLengthHeader = headers.getHeaders().getFirstValue("Content-Length"); if (contentLengthHeader != null) { if (Long.parseLong(contentLengthHeader) == -1L) { return AsyncHandler.STATE.ABORT; } } if (decoratedAsyncHandler != null) { return decoratedAsyncHandler.onHeadersReceived(headers); } return AsyncHandler.STATE.CONTINUE; }
/** * Creates a new multipart entity containing the given parts. * @param parts The parts to include. */ public MultipartRequestEntity(List<Part> parts, FluentCaseInsensitiveStringsMap requestHeaders) { if (parts == null) throw new NullPointerException("parts"); this.parts = parts; String contentTypeHeader = requestHeaders.getFirstValue("Content-Type"); if (isNonEmpty(contentTypeHeader)) { int boundaryLocation = contentTypeHeader.indexOf("boundary="); if (boundaryLocation != -1) { // boundary defined in existing Content-Type contentType = contentTypeHeader; multipartBoundary = (contentTypeHeader.substring(boundaryLocation + "boundary=".length()).trim()).getBytes(US_ASCII); } else { // generate boundary and append it to existing Content-Type multipartBoundary = generateMultipartBoundary(); contentType = computeContentType(contentTypeHeader); } } else { multipartBoundary = generateMultipartBoundary(); contentType = computeContentType(MULTIPART_FORM_CONTENT_TYPE); } contentLength = MultipartUtils.getLengthOfParts(parts, multipartBoundary); }
private <T> NettyResponseFuture<T> newNettyResponseFuture(Uri uri, Request request, AsyncHandler<T> asyncHandler, NettyRequest nettyRequest, ProxyServer proxyServer) { NettyResponseFuture<T> future = new NettyResponseFuture<>(// uri,// request,// asyncHandler,// nettyRequest,// config.getMaxRequestRetry(),// request.getConnectionPoolPartitioning(),// proxyServer); String expectHeader = request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT); if (expectHeader != null && expectHeader.equalsIgnoreCase(HttpHeaders.Values.CONTINUE)) future.setDontWriteBodyBecauseExpectContinue(true); return future; }
String contentType; String contentTypeHeader = requestHeaders.getFirstValue("Content-Type"); if (isNonEmpty(contentTypeHeader)) { int boundaryLocation = contentTypeHeader.indexOf("boundary=");
if (request.getHeaders().getFirstValue("Accept") == null) { urlConnection.setRequestProperty("Accept", "*/*"); if (request.getHeaders().getFirstValue("User-Agent") != null) { urlConnection.setRequestProperty("User-Agent", request.getHeaders().getFirstValue("User-Agent")); } else if (config.getUserAgent() != null) { urlConnection.setRequestProperty("User-Agent", config.getUserAgent());
/** * @see FluentCaseInsensitiveStringsMap#getFirstValue(String) */ public String getFirstValue(String key) { return headers.getFirstValue(key); }
/** * Set headers to this listener. * * @param headers * {@link FluentCaseInsensitiveStringsMap} */ public void headers(FluentCaseInsensitiveStringsMap headers) { this.headers = headers; // Netty 3 bug hack: last chunk is not notified, fixed in Netty 4 String contentLength = headers.getFirstValue("Content-Length"); if (contentLength != null) expectedTotal = Long.valueOf(contentLength); }
private void calculateTotal(HttpResponseHeaders headers) { String length = headers.getHeaders().getFirstValue("Content-Length"); try { total = Integer.valueOf(length); } catch (Exception e) { total = -1; } }
/** * Get number of Accounts matching the query params * * @param params {@link QueryParams} * @return Integer on success, null otherwise */ public Integer getAccountsCount(final QueryParams params) { FluentCaseInsensitiveStringsMap map = doHEAD(Accounts.ACCOUNTS_RESOURCE, params); return Integer.parseInt(map.getFirstValue(X_RECORDS_HEADER_NAME)); }
/** * Get number of Plans matching the query params * * @param params {@link QueryParams} * @return Integer on success, null otherwise */ public Integer getPlansCount(final QueryParams params) { FluentCaseInsensitiveStringsMap map = doHEAD(Plans.PLANS_RESOURCE, params); return Integer.parseInt(map.getFirstValue(X_RECORDS_HEADER_NAME)); }
/** * Return all the invoices given query params * <p> * * @param params {@link QueryParams} * @return the count of invoices matching the query */ public int getInvoicesCount(final QueryParams params) { FluentCaseInsensitiveStringsMap map = doHEAD(Invoices.INVOICES_RESOURCE, params); return Integer.parseInt(map.getFirstValue(X_RECORDS_HEADER_NAME)); }
@Test public void emptyValueTest() { FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(); map.add("foo", ""); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo"))); assertEquals(map.getFirstValue("foo"), ""); assertEquals(map.getJoinedValue("foo", ", "), ""); assertEquals(map.get("foo"), Arrays.asList("")); }
@Test public void nullValueTest() { FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(); map.add("foo", (String) null); assertEquals(map.getFirstValue("foo"), ""); assertEquals(map.getJoinedValue("foo", ", "), ""); assertEquals(map.get("foo").size(), 1); }
public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException { if (ctx.getResponseHeaders() != null && ctx.getResponseHeaders().getHeaders().getFirstValue("Ping").equals("Pong") && replay.getAndSet(false)) { Request request = new RequestBuilder(ctx.getRequest()).addHeader("Ping", "Pong").build(); return new FilterContext.FilterContextBuilder<T>().asyncHandler(ctx.getAsyncHandler()).request(request).replayRequest(true).build(); } return ctx; }