String s = proxy ? PROXY_AUTH_RESP : WWW_AUTH_RESP; Header header = new Header(s, auth, true); method.addRequestHeader(header); return true; } else {
if (httpHeaders != null) { for (String httpHeaderKey : httpHeaders.stringPropertyNames()) { method.addRequestHeader(new Header(httpHeaderKey, httpHeaders.getProperty(httpHeaderKey)));
String s = proxy ? PROXY_AUTH_RESP : WWW_AUTH_RESP; Header header = new Header(s, auth, true); method.addRequestHeader(header); return true; } else {
String authstring = authscheme.authenticate(credentials, method); if (authstring != null) { method.addRequestHeader(new Header(PROXY_AUTH_RESP, authstring, true));
String authstring = authscheme.authenticate(credentials, method); if (authstring != null) { method.addRequestHeader(new Header(WWW_AUTH_RESP, authstring, true));
Iterator i = defaults.iterator(); while (i.hasNext()) { method.addRequestHeader((Header)i.next());
private InputStream setupInputStream(URL url, Map<String, String> headers) throws IOException { HttpClient client = new HttpClient(); String uri = url.toExternalForm(); if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, "URL is " + uri); HttpMethod get = new GetMethod(uri); if (MapUtils.isNotEmpty(headers)) { for (String headerName : headers.keySet()) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log( Level.FINE, "Adding header " + headerName + " = " + headers.get(headerName)); } get.addRequestHeader(headerName, headers.get(headerName)); } } int code = client.executeMethod(get); if (code != 200) { throw new IOException("Connection returned code " + code); } return get.getResponseBodyAsStream(); } }
if (entity != null) { if (entity.getContentLength() > 0l) { httpMethod.addRequestHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(entity.getContentLength())); httpMethod.addRequestHeader(HttpHeaders.CONTENT_TYPE, entity .getContentType().toString());
public void addRequestHeader(String name, String value) { getMethod().addRequestHeader(name, value); }
@Override protected void adjustHttpHeader(HttpMethod method) { method.addRequestHeader(new Header("Authorization", getAuthHeaderValue())); }
/** * Prepares a Method object. * * @param method the HttpMethod. * @throws FileSystemException if an error occurs encoding the uri. * @throws URIException if the URI is in error. */ @Override protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException { final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset()); method.setPath(pathEncoded); method.setFollowRedirects(this.getFollowRedirect()); method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS"); method.addRequestHeader("Cache-control", "no-cache"); method.addRequestHeader("Cache-store", "no-store"); method.addRequestHeader("Pragma", "no-cache"); method.addRequestHeader("Expires", "0"); }
/** * Prepares a Method object. * * @param method the HttpMethod. * @throws FileSystemException if an error occurs encoding the uri. * @throws URIException if the URI is in error. */ @Override protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException { final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset()); method.setPath(pathEncoded); method.setFollowRedirects(this.getFollowRedirect()); method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS"); method.addRequestHeader("Cache-control", "no-cache"); method.addRequestHeader("Cache-store", "no-store"); method.addRequestHeader("Pragma", "no-cache"); method.addRequestHeader("Expires", "0"); }
private void configureHttpMethod(HttpMethod httpMethod, boolean useContentCache, DiamondMeta diamondMeta, long onceTimeOut) { if (!useContentCache && null != diamondMeta) { String lastModifiedHeader = diamondMeta.getLastModifiedHeader(); if (null != lastModifiedHeader && !Constants.NULL.equals(lastModifiedHeader)) { httpMethod.addRequestHeader(Constants.IF_MODIFIED_SINCE, lastModifiedHeader); } if (null != diamondMeta.getMd5() && !Constants.NULL.equals(diamondMeta.getMd5())) { httpMethod.addRequestHeader(Constants.CONTENT_MD5, diamondMeta.getMd5()); } } httpMethod.addRequestHeader(Constants.ACCEPT_ENCODING, "gzip,deflate"); HttpMethodParams params = new HttpMethodParams(); params.setSoTimeout((int) onceTimeOut); httpMethod.setParams(params); }
protected final void setDoAuthentication(HttpMethod method) { if (authScope != null && httpClient.getState().getCredentials(authScope) != null) { method.setDoAuthentication(true); } else { //method.setDoAuthentication(false); } if (masqueradeAsUser != null) { method.addRequestHeader(new Header("x-masquerade-as-user", masqueradeAsUser)); } // TODO probably doesn't belong here, need another method that // HttpMethod objects pass through. method.addRequestHeader(new Header("Connection", "keep-alive")); }
private void execute() throws Exception { Method type = scenario.method(); int requests = scenario.requests(); for(int i = 0; i < requests; i++) { HttpMethod method = getMethod(type); try { method.addRequestHeader(RoundTripTest.REQUEST_ID, String.format("id-%s-%s", id, i)); client.executeMethod(method); analyse(method); } catch(Throwable e) { e.printStackTrace(); }finally { method.releaseConnection(); } } latch.countDown(); }
private void addHeaders(HttpMethod httpMethod) { httpMethod.setDoAuthentication(true); httpMethod.addRequestHeader("User-Agent", "Atlassian Tomcat API"); httpMethod.getHostAuthState().isPreemptive(); }
private void addHeaders(HttpMethod m, RestRequest request) { for (RestData.Header h : request.getHeaders()) { m.addRequestHeader(h.getName(), h.getValue()); } } }
private HttpClient setUpHttpClient(HttpMethod method) { HttpClient httpclient = new HttpClient(); httpclient.getParams().setAuthenticationPreemptive(true); httpclient.getState().setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(this.user, this.password) ); method.setDoAuthentication(true); method.addRequestHeader("Content-Type", "application/json"); return httpclient; }
private static void initHeaders(RequestOptions options, HttpMethod method) { String[] headers = options.getHeaderNames(); for (String header : headers) { Object[] values = options.getHeaders(header); for (Object value : values) { method.addRequestHeader(header, value.toString()); } } String cc = options.getCacheControl(); if (cc != null && cc.length() != 0) method.setRequestHeader("Cache-Control", cc); if (options.getAuthorization() != null) method.setDoAuthentication(false); }
@Override public void addAuthentication(HttpMethod forMethod, HttpClient forClient) { try { forMethod.addRequestHeader("Authorization", "token " + accessToken); String url = forMethod.getURI().toString(); String separator = url.contains("?") ? "&" : "?"; url += separator + "access_token=" + getAccessToken(); forMethod.setURI(new URI(url, true)); } catch (URIException e) { throw new SourceControlException("Failed to decode/encode given URI. " + e.getMessage(), e); } }