public void setRequestHeader(String name, String value) throws HTTPException { setRequestHeader(new BasicHeader(name, value)); }
@Deprecated public HTTPMethod setRequestHeader(String name, String value) throws HTTPException { return setRequestHeader(new BasicHeader(name, value)); }
private boolean rangeOk(String url) { HTTPMethod method = null; try { method = HTTPFactory.Get(session,url); method.setRequestHeader("Range", "bytes=" + 0 + "-" + 0); doConnect(method); int code = method.getStatusCode(); if (code != 206) throw new IOException("Server does not support Range requests, code= " + code); Header head = method.getResponseHeader("Content-Range"); total_length=Long.parseLong(head.getValue().substring(head.getValue().lastIndexOf("/")+1)); // clear stream method.close(); return true; } catch (IOException e) { return false; } finally { if (method != null) method.close(); } }
static private boolean checkIfRemoteNcml(String location) throws IOException { if (decodePathExtension(location)==ServiceType.NCML) { // just because location ends with ncml does not mean it's ncml // if the ncml file is being served up via http by a remote server, // we should be able to read the first bit of it and see if it even // looks like an ncml file. try (HTTPMethod method = HTTPFactory.Get(location)) { method.setRange(0, NUM_BYTES_TO_DETERMINE_NCML); method.setRequestHeader("accept-encoding", "identity"); int statusCode = method.execute(); if (statusCode >= 300) { if (statusCode == 401) { throw new IOException("Unauthorized to open dataset " + location); } else if (statusCode == 406) { String msg = location + " - this server does not support returning content without any encoding."; msg = msg + " Please download the file locally. Return status=" + statusCode; throw new IOException(msg); } else { throw new IOException(location + " is not a valid URL, return status=" + statusCode); } } return checkIfNcml(method.getResponseAsString()); } } return false; }
method = HTTPFactory.Get(session); method.setFollowRedirects(true); method.setRequestHeader("Range", "bytes=" + pos + "-" + end); doConnect(method);
private HTTPMethod getHttpResponse(URI uri) throws IOException { HTTPMethod method = null; try { method = HTTPFactory.Get(uri.toString()); method.getSession().setConnectionTimeout(this.connectionTimeout); method.getSession().setSoTimeout(this.socketTimeout); method.setFollowRedirects(this.followRedirects); method.setRequestHeader("Accept-Encoding", this.contentEncoding); method.execute(); int statusCode = method.getStatusCode(); if (statusCode == 200 || statusCode == 201) { return method; } method.execute(); return method; } catch (Throwable t) { if (method != null) method.close(); throw t; } } }