Exemplo n.º 1
0
 /**
  * returns lowercase set of tokens in 'connection' header.
  *
  * <p>rfc 2616:14.10: proxy must parse connection header and remove any fields with same name as
  * connection tokens.
  *
  * <p>HttpClient will add its own Connection headers to manage persistent connections between
  * proxy and server.
  */
 private static Set<String> getConnectionTokensFromRequest(HttpServletRequest req) {
   HeaderValueParser parser = new BasicHeaderValueParser();
   Enumeration<String> headers = req.getHeaders(CONNECTION_HEADER);
   Set<String> result = new HashSet<String>();
   while (headers.hasMoreElements()) {
     final String header = headers.nextElement();
     CharArrayBuffer buffer = new CharArrayBuffer(header.length() + 10);
     buffer.append(header);
     ParserCursor cursor = new ParserCursor(0, buffer.length());
     for (HeaderElement element : parser.parseElements(buffer, cursor)) {
       result.add(element.getName().toLowerCase());
     }
   }
   return result;
 }
Exemplo n.º 2
0
  @Override
  protected void parseChallenge(final CharArrayBuffer buffer, int pos, int len)
      throws MalformedChallengeException {
    HeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    ParserCursor cursor = new ParserCursor(pos, buffer.length());
    HeaderElement[] elements = parser.parseElements(buffer, cursor);
    if (elements.length == 0) {
      throw new MalformedChallengeException("Authentication challenge is empty");
    }

    this.params = new HashMap<String, String>(elements.length);
    for (HeaderElement element : elements) {
      this.params.put(element.getName(), element.getValue());
    }
  }