예제 #1
0
  private void removeHeader0(int h, int i, String name) {
    HeaderEntry e = entries[i];
    if (e == null) {
      return;
    }

    for (; ; ) {
      if (e.hash == h && eq(name, e.key)) {
        e.remove();
        HeaderEntry next = e.next;
        if (next != null) {
          entries[i] = next;
          e = next;
        } else {
          entries[i] = null;
          return;
        }
      } else {
        break;
      }
    }

    for (; ; ) {
      HeaderEntry next = e.next;
      if (next == null) {
        break;
      }
      if (next.hash == h && eq(name, next.key)) {
        e.next = next.next;
        next.remove();
      } else {
        e = next;
      }
    }
  }
예제 #2
0
  /**
   * @param name
   * @return String
   */
  public String getHeader(String name) {
    HeaderEntry entry = this.getHeaderEntry(name);

    if (entry != null) {
      return entry.getHeader();
    }
    return null;
  }
예제 #3
0
  /**
   * @param name
   * @return List<String>
   */
  public List<String> remove(String name) {
    HeaderEntry entry = this.getHeaderEntry(name);

    if (entry != null) {
      this.headers.remove(name.toLowerCase());
      return entry.getValues();
    }
    return null;
  }
예제 #4
0
  private void addHeader0(int h, int i, final String name, final String value) {
    // Update the hash table.
    HeaderEntry e = entries[i];
    HeaderEntry newEntry;
    entries[i] = newEntry = new HeaderEntry(h, name, value);
    newEntry.next = e;

    // Update the linked list.
    newEntry.addBefore(head);
  }
예제 #5
0
  /**
   * @param name
   * @return String[]
   */
  public String[] getHeaderValues(String name) {
    HeaderEntry entry = this.getHeaderEntry(name);

    if (entry != null) {
      List<String> values = entry.getValues();
      String[] result = new String[values.size()];
      values.toArray(result);
      return result;
    }
    return new String[0];
  }
예제 #6
0
  /**
   * @param name
   * @param newName
   * @param value
   */
  public void replace(String name, String newName, String value) {
    HeaderEntry entry = this.getHeaderEntry(name);

    if (entry != null) {
      this.headers.remove(entry);
      entry.setName(newName);
      entry.setValue(value, false);
      this.headers.put(newName.toLowerCase(), entry);
    } else {
      entry = new HeaderEntry(name, new String[] {value});
      this.headers.put(name.toLowerCase(), entry);
    }
  }
예제 #7
0
 private Map<String, List<String>> getHeaderFieldsDoNotForceResponse() {
   Map<String, List<String>> map = new HashMap<String, List<String>>();
   for (HeaderEntry entry : headers) {
     String k = entry.getKey();
     String v = entry.getValue();
     List<String> values = map.get(k);
     if (values == null) {
       values = new ArrayList<String>();
       map.put(k, values);
     }
     values.add(v);
   }
   return map;
 }
예제 #8
0
  /**
   * @param name
   * @param value
   * @param append
   */
  private void setHeader(String name, String value, boolean append) {
    if (value != null) {
      HeaderEntry entry = this.getHeaderEntry(name);

      if (entry != null) {
        entry.setValue(value, append);
      } else {
        entry = new HeaderEntry(name, new String[] {value});
        this.headers.put(name.toLowerCase(), entry);
      }
    } else {
      this.remove(name);
    }
  }
예제 #9
0
  /** @see java.lang.Object#toString() */
  @Override
  public String toString() {
    StringBuilder buffer = new StringBuilder();

    for (Map.Entry<String, HeaderEntry> entry : this.headers.entrySet()) {
      HeaderEntry headerEntry = entry.getValue();
      List<String> values = headerEntry.getValues();

      for (String value : values) {
        buffer.append(headerEntry.getName()).append(": ").append(value).append("\r\n");
      }
    }
    return buffer.toString();
  }
예제 #10
0
 private String getHeaderFieldDoNotForceResponse(String key) {
   for (int i = headers.size() - 1; i >= 0; i--) {
     HeaderEntry entry = headers.get(i);
     if (key == null) {
       if (entry.getKey() == null) {
         return entry.getValue();
       }
       continue;
     }
     if (key.equals(entry.getKey())) {
       return entry.getValue();
     }
   }
   return null;
 }
예제 #11
0
  @Override
  public HttpHeader clone() {
    HttpHeader httpHeader = new HttpHeader();

    for (Map.Entry<String, HeaderEntry> entry : this.headers.entrySet()) {
      String name = entry.getKey();
      HeaderEntry headerEntry = entry.getValue();
      List<String> values = headerEntry.getValues();

      for (String value : values) {
        httpHeader.addHeader(name, value);
      }
    }
    return httpHeader;
  }
예제 #12
0
 HttpHeaders() {
   head.before = head.after = head;
 }
예제 #13
0
 void addBefore(HeaderEntry e) {
   after = e;
   before = e.before;
   before.after = this;
   after.before = this;
 }
예제 #14
0
 void remove() {
   before.after = after;
   after.before = before;
 }
예제 #15
0
 void clearHeaders() {
   for (int i = 0; i < entries.length; i++) {
     entries[i] = null;
   }
   head.before = head.after = head;
 }