if (HTTP.CHUNK_CODING.equalsIgnoreCase(s)) { if (message.getProtocolVersion().lessEquals(HttpVersion.HTTP_1_0)) { throw new ProtocolException( "Chunked transfer encoding not allowed for " + message.getProtocolVersion()); return IDENTITY; } else { throw new ProtocolException( "Unsupported transfer encoding: " + s); return len; } catch (NumberFormatException e) { throw new ProtocolException("Invalid content length: " + s);
encodings = transferEncodingHeader.getElements(); } catch (ParseException px) { throw new ProtocolException ("Invalid Transfer-Encoding header value: " + transferEncodingHeader, px); && !encoding.equalsIgnoreCase(HTTP.CHUNK_CODING) && !encoding.equalsIgnoreCase(HTTP.IDENTITY_CODING)) { throw new ProtocolException("Unsupported transfer encoding: " + encoding); } else { if (strict) { throw new ProtocolException("Chunk-encoding must be the last one applied"); Header[] headers = message.getHeaders(HTTP.CONTENT_LEN); if (strict && headers.length > 1) { throw new ProtocolException("Multiple content length headers"); } catch (NumberFormatException e) { if (strict) { throw new ProtocolException("Invalid content length: " + header.getValue());
if (locationHeader == null) { throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); uri = new URI(location); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex);
return; } else { throw new ProtocolException("Target host missing");
public RequestWrapper(final HttpRequest request) throws ProtocolException { super(); if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } this.original = request; setParams(request.getParams()); // Make a copy of the original URI if (request instanceof HttpUriRequest) { this.uri = ((HttpUriRequest) request).getURI(); this.method = ((HttpUriRequest) request).getMethod(); this.version = null; } else { RequestLine requestLine = request.getRequestLine(); try { this.uri = new URI(requestLine.getUri()); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid request URI: " + requestLine.getUri(), ex); } this.method = requestLine.getMethod(); this.version = request.getProtocolVersion(); } this.execCount = 0; }
public HttpMessage parse() throws IOException, HttpException { HttpMessage message = null; try { message = parseHead(this.sessionBuffer); } catch (ParseException px) { throw new ProtocolException(px.getMessage(), px); } Header[] headers = AbstractMessageParser.parseHeaders( this.sessionBuffer, this.maxHeaderCount, this.maxLineLen, this.lineParser); message.setHeaders(headers); return message; }
throw new ProtocolException("Transfer-encoding header already present"); throw new ProtocolException("Content-Length header already present");
throw new ProtocolException("Transfer-encoding header already present"); throw new ProtocolException("Content-Length header already present"); throw new ProtocolException( "Chunked transfer encoding not allowed for " + ver);
requestURI = new URI(request.getRequestLine().getUri()); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid request URI: " + request.getRequestLine().getUri(), ex);
protected void rewriteRequestURI( final RequestWrapper request, final HttpRoute route) throws ProtocolException { try { URI uri = request.getURI(); if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { HttpHost target = route.getTargetHost(); uri = URIUtils.rewriteURI(uri, target); request.setURI(uri); } } else { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, null); request.setURI(uri); } } } catch (URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }
protected void rewriteRequestURI( final RequestWrapper request, final HttpRoute route) throws ProtocolException { try { URI uri = request.getURI(); if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { HttpHost target = route.getTargetHost(); uri = URIUtils.rewriteURI(uri, target); request.setURI(uri); } } else { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, null); request.setURI(uri); } } } catch (URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }
headers[i] = parser.parseHeader(buffer); } catch (ParseException ex) { throw new ProtocolException(ex.getMessage());
@Override protected HttpMessage parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException { // clear the buffer this.lineBuf.clear(); //read out the HTTP status string int count = 0; ParserCursor cursor = null; do { int i = sessionBuffer.readLine(this.lineBuf); if (i == -1 && count == 0) { // The server just dropped connection on us throw new NoHttpResponseException("The target server failed to respond"); } cursor = new ParserCursor(0, this.lineBuf.length()); if (lineParser.hasProtocolVersion(this.lineBuf, cursor)) { // Got one break; } else if (i == -1 || count >= this.maxGarbageLines) { // Giving up throw new ProtocolException("The server failed to respond with a " + "valid HTTP response"); } count++; } while(true); //create the status line from the status string StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor); return this.responseFactory.newHttpResponse(statusline, null); }
@Override public long determineLength(final HttpMessage message) throws HttpException { final long result = this.contentLengthStrategy.determineLength(message); if (result == ContentLengthStrategy.IDENTITY) { throw new ProtocolException("Identity transfer encoding cannot be used"); } return result; }
public long determineLength(final HttpMessage message) throws HttpException { final long result = this.contentLengthStrategy.determineLength(message); if (result == ContentLengthStrategy.IDENTITY) { throw new ProtocolException("Identity transfer encoding cannot be used"); } return result; }
public long determineLength(final HttpMessage message) throws HttpException { final long result = this.contentLengthStrategy.determineLength(message); if (result == ContentLengthStrategy.IDENTITY) { throw new ProtocolException("Identity transfer encoding cannot be used"); } return result; }
@Override protected URI createLocationURI(String location) throws ProtocolException { try { return new URI(location).normalize(); } catch (URISyntaxException e) { try { return parseLenient(location).normalize(); } catch (URISyntaxException f) { throw new ProtocolException("Invalid redirect URI: " + location, e); } } }
void rewriteRequestURI( final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException { final URI uri = request.getURI(); if (uri != null) { try { request.setURI(URIUtils.rewriteURIForRoute(uri, route)); } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + uri, ex); } } }
void rewriteRequestURI( final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException { final URI uri = request.getURI(); if (uri != null) { try { request.setURI(URIUtils.rewriteURIForRoute(uri, route)); } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + uri, ex); } } }
void rewriteRequestURI( final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException { final URI uri = request.getURI(); if (uri != null) { try { request.setURI(URIUtils.rewriteURIForRoute(uri, route)); } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + uri, ex); } } }