/** * Assures that the browser does not download any binary files in textmode * * @param request * @throws BrowserException */ private void checkContentLengthLimit(final Request request) throws BrowserException { long length = -1; if (request == null || request.getHttpConnection() == null || (length = request.getHttpConnection().getLongContentLength()) < 0) { return; } else if (length > this.limit) { final Logger llogger = this.getLogger(); if (llogger != null) { llogger.severe(request.printHeaders()); } throw new BrowserException("Content-length too big", request.getHttpConnection()); } }
/** * Reads the content behind a con and returns them. Note: if con==null, the current request is * read. This is usefull for redirects. Note #2: if a connection is loaded, data is not stored in * the browser instance. * * @param con * @return * @throws IOException */ public Request loadConnection(HTTPConnectionImpl con) throws IOException { Request requ; if (con == null) { requ = this.request; } else { requ = new Request(con) { { this.requested = true; } @Override public long postRequest() throws IOException { return 0; } @Override public void preRequest() throws IOException {} }; } try { this.checkContentLengthLimit(requ); con = requ.getHttpConnection(); /* we update allowedResponseCodes here */ con.setAllowedResponseCodes(this.allowedResponseCodes); requ.read(); } catch (final BrowserException e) { throw e; } catch (final IOException e) { throw new BrowserException(e.getMessage(), con, e); } finally { try { con.disconnect(); } catch (final Throwable e) { } } if (this.isVerbose()) { final Logger llogger = this.getLogger(); if (llogger != null) { llogger.finest("\r\n" + requ + "\r\n"); } } return requ; }