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; } } }
/** * @param name * @return String */ public String getHeader(String name) { HeaderEntry entry = this.getHeaderEntry(name); if (entry != null) { return entry.getHeader(); } return null; }
/** * @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; }
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); }
/** * @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]; }
/** * @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); } }
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; }
/** * @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); } }
/** @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(); }
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; }
@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; }
HttpHeaders() { head.before = head.after = head; }
void addBefore(HeaderEntry e) { after = e; before = e.before; before.after = this; after.before = this; }
void remove() { before.after = after; after.before = before; }
void clearHeaders() { for (int i = 0; i < entries.length; i++) { entries[i] = null; } head.before = head.after = head; }