/** * Create a <tt>"Cookie"</tt> {@link Header} containing all {@link Cookie}s * in <i>cookies</i>. * @param cookies an array of {@link Cookie}s to be formatted as a <tt>" * Cookie"</tt> header * @return a <tt>"Cookie"</tt> {@link Header}. */ public Header formatCookieHeader(Cookie[] cookies) { LOG.trace("enter CookieSpecBase.formatCookieHeader(Cookie[])"); return new Header("Cookie", formatCookies(cookies)); }
/** * Create a <tt>"Cookie"</tt> {@link Header} containing the {@link Cookie}. * @param cookie <tt>Cookie</tt>s to be formatted as a <tt>Cookie</tt> * header * @return a Cookie header. */ public Header formatCookieHeader(Cookie cookie) { LOG.trace("enter CookieSpecBase.formatCookieHeader(Cookie)"); return new Header("Cookie", formatCookie(cookie)); }
/** * Set the specified request header, overwriting any previous value. Note * that header-name matching is case-insensitive. * * @param headerName the header's name * @param headerValue the header's value */ public void setRequestHeader(String headerName, String headerValue) { Header header = new Header(headerName, headerValue); setRequestHeader(header); }
/** * Adds the specified request header, NOT overwriting any previous value. * Note that header-name matching is case insensitive. * * @param headerName the header's name * @param headerValue the header's value */ public void addRequestHeader(String headerName, String headerValue) { addRequestHeader(new Header(headerName, headerValue)); }
/** * Gets a header representing all of the header values with the given name. * If more that one header with the given name exists the values will be * combined with a "," as per RFC 2616. * * <p>Header name comparison is case insensitive. * * @param name the name of the header(s) to get * @return a header with a condensed value or <code>null</code> if no * headers by the given name are present */ public Header getCondensedHeader(String name) { Header[] headers = getHeaders(name); if (headers.length == 0) { return null; } else if (headers.length == 1) { return new Header(headers[0].getName(), headers[0].getValue()); } else { StringBuffer valueBuffer = new StringBuffer(headers[0].getValue()); for (int i = 1; i < headers.length; i++) { valueBuffer.append(", "); valueBuffer.append(headers[i].getValue()); } return new Header(name.toLowerCase(), valueBuffer.toString()); } }
public HeaderProcessor(Settings settings) { Map<String, String> workingHeaders = new HashMap<String, String>(); for (Map.Entry<Object, Object> prop : settings.asProperties().entrySet()) { String key = prop.getKey().toString(); if (key.startsWith(ES_NET_HTTP_HEADER_PREFIX)) { String headerName = key.substring(ES_NET_HTTP_HEADER_PREFIX.length()); validateName(headerName, prop); ensureNotReserved(headerName, workingHeaders); workingHeaders.put(headerName, extractHeaderValue(prop.getValue())); } } this.headers = new ArrayList<Header>(workingHeaders.keySet().size()); for (Map.Entry<String, String> headerData : workingHeaders.entrySet()) { headers.add(new Header(headerData.getKey(), headerData.getValue())); } for (ReservedHeaders reservedHeaders : ReservedHeaders.values()) { headers.add(new Header(reservedHeaders.getName(), reservedHeaders.getDefaultValue())); } }
public Header getVersionHeader() { ParameterFormatter formatter = new ParameterFormatter(); StringBuffer buffer = new StringBuffer(); formatter.format(buffer, new NameValuePair("$Version", Integer.toString(getVersion()))); return new Header("Cookie2", buffer.toString(), true); }
public class MainActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); List<Item> items = new ArrayList<Item>(); items.add(new Header("Header 1")); items.add(new ListItem("Text 1", "Rabble rabble")); items.add(new ListItem("Text 2", "Rabble rabble")); items.add(new ListItem("Text 3", "Rabble rabble")); items.add(new ListItem("Text 4", "Rabble rabble")); items.add(new Header("Header 2")); items.add(new ListItem("Text 5", "Rabble rabble")); items.add(new ListItem("Text 6", "Rabble rabble")); items.add(new ListItem("Text 7", "Rabble rabble")); items.add(new ListItem("Text 8", "Rabble rabble")); TwoTextArrayAdapter adapter = new TwoTextArrayAdapter(this, items); setListAdapter(adapter); } }
if (auth != null) { String s = proxy ? PROXY_AUTH_RESP : WWW_AUTH_RESP; Header header = new Header(s, auth, true); method.addRequestHeader(header); return true;
@Test public void testApplyArrayValues() throws Exception { Settings settings = new TestSettings(); settings.asProperties().put("es.net.http.header.Accept-Encoding", new Object[]{"gzip","deflate"}); Header[] headers = applyHeaders(settings); assertThat(headers, arrayWithSize(3)); assertThat(headers, arrayContainingInAnyOrder( new Header("Accept", "application/json"), new Header("Content-Type", "application/json"), new Header("Accept-Encoding", "gzip,deflate") )); }
if (httpHeaders != null) { for (String httpHeaderKey : httpHeaders.stringPropertyNames()) { method.addRequestHeader(new Header(httpHeaderKey, httpHeaders.getProperty(httpHeaderKey)));
@Test public void testApplyValidHeader() throws Exception { Settings settings = new TestSettings(); settings.setProperty("es.net.http.header.Max-Forwards", "10"); Header[] headers = applyHeaders(settings); assertThat(headers, arrayWithSize(3)); assertThat(headers, arrayContainingInAnyOrder( new Header("Accept", "application/json"), new Header("Content-Type", "application/json"), new Header("Max-Forwards", "10") )); }
/** * Returns the request's charset. The charset is parsed from the request entity's * content type, unless the content type header has been set manually. * * @see RequestEntity#getContentType() * * @since 3.0 */ public String getRequestCharSet() { if (getRequestHeader("Content-Type") == null) { // check the content type from request entity // We can't call getRequestEntity() since it will probably call // this method. if (this.requestEntity != null) { return getContentCharSet( new Header("Content-Type", requestEntity.getContentType())); } else { return super.getRequestCharSet(); } } else { return super.getRequestCharSet(); } }
@Test public void testApplyMultiValues() throws Exception { Settings settings = new TestSettings(); settings.setProperty("es.net.http.header.Accept-Encoding", "gzip,deflate"); Header[] headers = applyHeaders(settings); assertThat(headers, arrayWithSize(3)); assertThat(headers, arrayContainingInAnyOrder( new Header("Accept", "application/json"), new Header("Content-Type", "application/json"), new Header("Accept-Encoding", "gzip,deflate") )); } }
if (auth != null) { String s = proxy ? PROXY_AUTH_RESP : WWW_AUTH_RESP; Header header = new Header(s, auth, true); method.addRequestHeader(header); return true;
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));
protected void setContentType(HttpResponse response, MuleMessage message) { if(contentType == null) { contentType = getDefaultContentType(message); } response.setHeader(new Header(HttpConstants.HEADER_CONTENT_TYPE, parse(contentType, message))); }