@Test(expected = NotImplementedException.class) public void testEntityWithIdentityTransferEncoding() throws Exception { final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy(); final HttpMessage message = new TestHttpMessage(); message.addHeader("Transfer-Encoding", "Identity"); lenStrategy.determineLength(message); }
@Override public long determineLength(final HttpMessage message) throws HttpException { Args.notNull(message, "HTTP message"); final Header transferEncodingHeader = message.getFirstHeader(HttpHeaders.TRANSFER_ENCODING); if (transferEncodingHeader != null) { final String headerValue = transferEncodingHeader.getValue(); if (HeaderElements.CHUNKED_ENCODING.equalsIgnoreCase(headerValue)) { return CHUNKED; } throw new NotImplementedException("Unsupported transfer encoding: " + headerValue); } if (message.countHeaders(HttpHeaders.CONTENT_LENGTH) > 1) { throw new ProtocolException("Multiple Content-Length headers"); } final Header contentLengthHeader = message.getFirstHeader(HttpHeaders.CONTENT_LENGTH); if (contentLengthHeader != null) { final String s = contentLengthHeader.getValue(); try { final long len = Long.parseLong(s); if (len < 0) { throw new ProtocolException("Negative content length: " + s); } return len; } catch (final NumberFormatException e) { throw new ProtocolException("Invalid content length: " + s); } } return UNDEFINED; }
DefaultContentLengthStrategy implements ContentLengthStrategy { @Override public long determineLength(final HttpMessage message) throws HttpException { Args.notNull(message, "HTTP message"); final Header transferEncodingHeader = message.getFirstHeader(HttpHeaders.TRANSFER_ENCODING); if (transferEncodingHeader != null) { final String headerValue = transferEncodingHeader.getValue(); if (HeaderElements.CHUNKED_ENCODING.equalsIgnoreCase(headerValue)) { return CHUNKED; } throw new NotImplementedException("Unsupported transfer encoding: " + headerValue); } if (message.countHeaders(HttpHeaders.CONTENT_LENGTH) > 1) { throw new ProtocolException("Multiple Content-Length headers"); } final Header contentLengthHeader = message.getFirstHeader(HttpHeaders.CONTENT_LENGTH); if (contentLengthHeader != null) { final String s = contentLengthHeader.getValue(); try { final long len = Long.parseLong(s); if (len < 0) { throw new ProtocolException("Negative content length: " + s); } return len; } catch (final NumberFormatException e) { throw new ProtocolException("Invalid content length: " + s); } } return UNDEFINED; } }
DefaultContentLengthStrategy implements ContentLengthStrategy { @Override public long determineLength(final HttpMessage message) throws HttpException { Args.notNull(message, "HTTP message"); final Header transferEncodingHeader = message.getFirstHeader(HttpHeaders.TRANSFER_ENCODING); if (transferEncodingHeader != null) { final String headerValue = transferEncodingHeader.getValue(); if (HeaderElements.CHUNKED_ENCODING.equalsIgnoreCase(headerValue)) { return CHUNKED; } throw new NotImplementedException("Unsupported transfer encoding: " + headerValue); } if (message.countHeaders(HttpHeaders.CONTENT_LENGTH) > 1) { throw new ProtocolException("Multiple Content-Length headers"); } final Header contentLengthHeader = message.getFirstHeader(HttpHeaders.CONTENT_LENGTH); if (contentLengthHeader != null) { final String s = contentLengthHeader.getValue(); try { final long len = Long.parseLong(s); if (len < 0) { throw new ProtocolException("Negative content length: " + s); } return len; } catch (final NumberFormatException e) { throw new ProtocolException("Invalid content length: " + s); } } return UNDEFINED; } DefaultContentLengthStrategy(); }
DefaultContentLengthStrategy implements ContentLengthStrategy { @Override public long determineLength(final HttpMessage message) throws HttpException { Args.notNull(message, "HTTP message"); final Header transferEncodingHeader = message.getFirstHeader(HttpHeaders.TRANSFER_ENCODING); if (transferEncodingHeader != null) { final String headerValue = transferEncodingHeader.getValue(); if (HeaderElements.CHUNKED_ENCODING.equalsIgnoreCase(headerValue)) { return CHUNKED; } throw new NotImplementedException("Unsupported transfer encoding: " + headerValue); } if (message.countHeaders(HttpHeaders.CONTENT_LENGTH) > 1) { throw new ProtocolException("Multiple Content-Length headers"); } final Header contentLengthHeader = message.getFirstHeader(HttpHeaders.CONTENT_LENGTH); if (contentLengthHeader != null) { final String s = contentLengthHeader.getValue(); try { final long len = Long.parseLong(s); if (len < 0) { throw new ProtocolException("Negative content length: " + s); } return len; } catch (final NumberFormatException e) { throw new ProtocolException("Invalid content length: " + s); } } return UNDEFINED; } DefaultContentLengthStrategy(); @Override long determineLength(final HttpMessage message); }
DefaultContentLengthStrategy implements ContentLengthStrategy { @Override public long determineLength(final HttpMessage message) throws HttpException { Args.notNull(message, "HTTP message"); final Header transferEncodingHeader = message.getFirstHeader(HttpHeaders.TRANSFER_ENCODING); if (transferEncodingHeader != null) { final String headerValue = transferEncodingHeader.getValue(); if (HeaderElements.CHUNKED_ENCODING.equalsIgnoreCase(headerValue)) { return CHUNKED; } throw new NotImplementedException("Unsupported transfer encoding: " + headerValue); } if (message.countHeaders(HttpHeaders.CONTENT_LENGTH) > 1) { throw new ProtocolException("Multiple Content-Length headers"); } final Header contentLengthHeader = message.getFirstHeader(HttpHeaders.CONTENT_LENGTH); if (contentLengthHeader != null) { final String s = contentLengthHeader.getValue(); try { final long len = Long.parseLong(s); if (len < 0) { throw new ProtocolException("Negative content length: " + s); } return len; } catch (final NumberFormatException e) { throw new ProtocolException("Invalid content length: " + s); } } return UNDEFINED; } DefaultContentLengthStrategy(); @Override long determineLength(final HttpMessage message); static final DefaultContentLengthStrategy INSTANCE; }