use of org.apache.commons.httpclient.Header in project sling by apache.
the class HeadServletTest method assertResponseHeader.
private void assertResponseHeader(HttpMethod m, String name, String expectedRegex) {
final Header h = m.getResponseHeader(name);
assertNotNull("Expecting header " + name, h);
final String value = h.getValue();
assertTrue("Expected regexp " + expectedRegex + " for header " + name + ", header value is " + value, Pattern.matches(expectedRegex, value));
}
use of org.apache.commons.httpclient.Header in project nutch by apache.
the class Http method configureClient.
/**
* Configures the HTTP client
*/
private void configureClient() {
// Set up an HTTPS socket factory that accepts self-signed certs.
// ProtocolSocketFactory factory = new SSLProtocolSocketFactory();
ProtocolSocketFactory factory = new DummySSLProtocolSocketFactory();
Protocol https = new Protocol("https", factory, 443);
Protocol.registerProtocol("https", https);
HttpConnectionManagerParams params = connectionManager.getParams();
params.setConnectionTimeout(timeout);
params.setSoTimeout(timeout);
params.setSendBufferSize(BUFFER_SIZE);
params.setReceiveBufferSize(BUFFER_SIZE);
// --------------------------------------------------------------------------------
// NUTCH-1836: Modification to increase the number of available connections
// for multi-threaded crawls.
// --------------------------------------------------------------------------------
params.setMaxTotalConnections(conf.getInt("mapred.tasktracker.map.tasks.maximum", 5) * conf.getInt("fetcher.threads.fetch", maxThreadsTotal));
// Also set max connections per host to maxThreadsTotal since all threads
// might be used to fetch from the same host - otherwise timeout errors can
// occur
params.setDefaultMaxConnectionsPerHost(conf.getInt("fetcher.threads.fetch", maxThreadsTotal));
// executeMethod(HttpMethod) seems to ignore the connection timeout on the
// connection manager.
// set it explicitly on the HttpClient.
client.getParams().setConnectionManagerTimeout(timeout);
HostConfiguration hostConf = client.getHostConfiguration();
ArrayList<Header> headers = new ArrayList<Header>();
// Note: some header fields (e.g., "User-Agent") are set per GET request
if (!acceptLanguage.isEmpty()) {
headers.add(new Header("Accept-Language", acceptLanguage));
}
if (!acceptCharset.isEmpty()) {
headers.add(new Header("Accept-Charset", acceptCharset));
}
if (!accept.isEmpty()) {
headers.add(new Header("Accept", accept));
}
// accept gzipped content
headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate"));
hostConf.getParams().setParameter("http.default-headers", headers);
// HTTP proxy server details
if (useProxy) {
hostConf.setProxy(proxyHost, proxyPort);
if (proxyUsername.length() > 0) {
AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm);
NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, Http.agentHost, this.proxyRealm);
client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
}
}
}
use of org.apache.commons.httpclient.Header in project knime-core by knime.
the class AbstractFileDownloadTripleProvider method getInputStream.
private static InputStream getInputStream(final GetMethod method) throws IOException {
InputStream in = method.getResponseBodyAsStream();
Header encoding = method.getResponseHeader("Content-Encoding");
if (encoding != null && encoding.getValue().equals("gzip")) {
in = new GZIPInputStream(in);
}
return in;
}
Aggregations