/** * Returns an array of {@link HeaderElement}s * constructed from my value. * * @see HeaderElement#parseElements(String) * * @return an array of header elements * * @since 3.0 */ public HeaderElement[] getElements() { return HeaderElement.parseElements(getValue()); }
/** * Returns an array of {@link HeaderElement}s * constructed from my value. * * @see HeaderElement#parse * @throws HttpException if the header cannot be parsed * @return an array of header elements * * @deprecated Use #getElements */ public HeaderElement[] getValues() throws HttpException { return HeaderElement.parse(getValue()); }
/** * Extracts a map of challenges ordered by authentication scheme name * * @param headers the array of authorization challenges * @return a map of authorization challenges * * @throws MalformedChallengeException if any of challenge strings * is malformed * * @since 3.0 */ public static Map parseChallenges(final Header[] headers) throws MalformedChallengeException { if (headers == null) { throw new IllegalArgumentException("Array of challenges may not be null"); } String challenge = null; Map challengemap = new HashMap(headers.length); for (int i = 0; i < headers.length; i++) { challenge = headers[i].getValue(); String s = AuthChallengeParser.extractScheme(challenge); challengemap.put(s, challenge); } return challengemap; } }
/** * <p> * This implementation will parse the <tt>Allow</tt> header to obtain * the set of methods supported by the resource identified by the Request-URI. * </p> * * @param state the {@link HttpState state} information associated with this method * @param conn the {@link HttpConnection connection} used to execute * this HTTP method * * @see #readResponse * @see #readResponseHeaders * @since 2.0 */ protected void processResponseHeaders(HttpState state, HttpConnection conn) { LOG.trace("enter OptionsMethod.processResponseHeaders(HttpState, HttpConnection)"); Header allowHeader = getResponseHeader("allow"); if (allowHeader != null) { String allowHeaderValue = allowHeader.getValue(); StringTokenizer tokenizer = new StringTokenizer(allowHeaderValue, ","); while (tokenizer.hasMoreElements()) { String methodAllowed = tokenizer.nextToken().trim().toUpperCase(); methodsAllowed.addElement(methodAllowed); } } }
/** * 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()); } }
/** * Return the header field * @param name the name of the header * @return the header field. * @see java.net.HttpURLConnection#getHeaderField(String) * @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders() */ public String getHeaderField(String name) { LOG.trace("enter HttpURLConnection.getHeaderField(String)"); // Note: Return the last matching header in the Header[] array, as in // the JDK implementation. Header[] headers = this.method.getResponseHeaders(); for (int i = headers.length - 1; i >= 0; i--) { if (headers[i].getName().equalsIgnoreCase(name)) { return headers[i].getValue(); } } return null; }
throw new IllegalArgumentException("Header may not be null."); return parse(host, port, path, secure, header.getValue());
Header header = headers[i]; try { return Long.parseLong(header.getValue()); } catch (NumberFormatException e) { if (LOG.isWarnEnabled()) {
Map challengemap = new HashMap(challenges.length); for (int i = 0; i < challenges.length; i++) { challenge = challenges[i].getValue(); String s = AuthChallengeParser.extractScheme(challenge); challengemap.put(s, challenge);
/** * Return the header field at the specified position * @param position The position * @return The header field. * @see java.net.HttpURLConnection#getHeaderField(int) * @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders() */ public String getHeaderField(int position) { LOG.trace("enter HttpURLConnection.getHeaderField(int)"); // Note: HttpClient does not consider the returned Status Line as // a response header. However, getHeaderField(0) is supposed to // return the status line. Hence the special case below ... if (position == 0) { return this.method.getStatusLine().toString(); } // Note: HttpClient does not currently keep headers in the same order // that they are read from the HTTP server. Header[] headers = this.method.getResponseHeaders(); if (position < 0 || position > headers.length) { return null; } return headers[position - 1].getValue(); }
if (connectionHeader.getValue().equalsIgnoreCase("close")) { if (LOG.isDebugEnabled()) { LOG.debug("Should close connection in response to directive: " + connectionHeader.getValue()); } else if (connectionHeader.getValue().equalsIgnoreCase("keep-alive")) { if (LOG.isDebugEnabled()) { LOG.debug("Should NOT close connection in response to directive: " + connectionHeader.getValue());
String redirectedReqString = firstPutReq.getResponseHeader(LOCATION).getValue(); PutMethod redirectedReq = new PutMethod(redirectedReqString); File localFile = new File(localFilePath);
throw new SchemaRegistryException( "Error reading schema id returned by registerSchema call: headers.length = " + headers.length); } else if (!headers[0].getValue().startsWith(SCHEMA_ID_HEADER_PREFIX)) { throw new SchemaRegistryException( "Error parsing schema id returned by registerSchema call: header = " + headers[0].getValue()); } else { LOG.info("Registered schema successfully"); schemaKey = headers[0].getValue().substring(SCHEMA_ID_HEADER_PREFIX.length());
throw new SchemaRegistryException( "Error reading schema id returned by registerSchema call: headers.length = " + headers.length); } else if (!headers[0].getValue().startsWith(SCHEMA_ID_HEADER_PREFIX)) { throw new SchemaRegistryException( "Error parsing schema id returned by registerSchema call: header = " + headers[0].getValue()); } else { LOG.info("Registered schema successfully"); schemaKey = headers[0].getValue().substring(SCHEMA_ID_HEADER_PREFIX.length());
if (connectionHeader.getValue().equalsIgnoreCase("close")) { if (LOG.isWarnEnabled()) { LOG.warn("Invalid header encountered '" + connectionHeader.toExternalForm()
if (LOG.isWarnEnabled()) { LOG.warn("Invalid cookie header: \"" + header.getValue() + "\". " + e.getMessage());
return false; String location = locationHeader.getValue(); if (LOG.isDebugEnabled()) { LOG.debug("Redirect requested to location '" + location + "'");