annotate src/org/eclipse/jetty/http/HttpFields.java @ 1020:6be43ef1eb96

HttpHeaderValues uses StringCache
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Oct 2016 22:24:41 -0600
parents f126d30e04a4
children e350c11242be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.http;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.io.UnsupportedEncodingException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.text.SimpleDateFormat;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import java.util.ArrayList;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import java.util.Calendar;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import java.util.Collections;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import java.util.Collection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import java.util.Date;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import java.util.Enumeration;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import java.util.GregorianCalendar;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import java.util.HashMap;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import java.util.Iterator;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import java.util.List;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import java.util.Locale;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import java.util.Map;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import java.util.NoSuchElementException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 import java.util.StringTokenizer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 import java.util.TimeZone;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 import java.util.concurrent.ConcurrentHashMap;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 import java.util.concurrent.ConcurrentMap;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import org.eclipse.jetty.io.Buffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 import org.eclipse.jetty.io.BufferCache;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 import org.eclipse.jetty.io.BufferCache.CachedBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 import org.eclipse.jetty.io.BufferUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 import org.eclipse.jetty.io.ByteArrayBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 import org.eclipse.jetty.util.LazyList;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 import org.eclipse.jetty.util.QuotedStringTokenizer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 import org.eclipse.jetty.util.StringUtil;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
50 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 * HTTP Fields. A collection of HTTP header and or Trailer fields.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 * <p>This class is not synchronized as it is expected that modifications will only be performed by a
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 * single thread.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 */
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
62 public final class HttpFields
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 {
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 private static final Logger LOG = LoggerFactory.getLogger(HttpFields.class);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
66 private static final String __COOKIE_DELIM="\"\\\n\r\t\f\b%+ ;=";
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
67 private static final TimeZone __GMT = TimeZone.getTimeZone("GMT");
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 private static final String[] DAYS =
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 { "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 private static final String[] MONTHS =
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan"};
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 private static class DateGenerator
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 private final StringBuilder buf = new StringBuilder(32);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 private final GregorianCalendar gc = new GregorianCalendar(__GMT);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 * Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 public String formatDate(long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 buf.setLength(0);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 gc.setTimeInMillis(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 int day_of_week = gc.get(Calendar.DAY_OF_WEEK);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 int day_of_month = gc.get(Calendar.DAY_OF_MONTH);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 int month = gc.get(Calendar.MONTH);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 int year = gc.get(Calendar.YEAR);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 int century = year / 100;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 year = year % 100;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 int hours = gc.get(Calendar.HOUR_OF_DAY);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 int minutes = gc.get(Calendar.MINUTE);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 int seconds = gc.get(Calendar.SECOND);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 buf.append(DAYS[day_of_week]);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 buf.append(',');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 StringUtil.append2digits(buf, day_of_month);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 buf.append(MONTHS[month]);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 StringUtil.append2digits(buf, century);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 StringUtil.append2digits(buf, year);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 StringUtil.append2digits(buf, hours);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 buf.append(':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 StringUtil.append2digits(buf, minutes);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 buf.append(':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 StringUtil.append2digits(buf, seconds);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 buf.append(" GMT");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 return buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 * Format "EEE, dd-MMM-yy HH:mm:ss 'GMT'" for cookies
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 public void formatCookieDate(StringBuilder buf, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 gc.setTimeInMillis(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 int day_of_week = gc.get(Calendar.DAY_OF_WEEK);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 int day_of_month = gc.get(Calendar.DAY_OF_MONTH);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 int month = gc.get(Calendar.MONTH);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 int year = gc.get(Calendar.YEAR);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 year = year % 10000;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 int epoch = (int) ((date / 1000) % (60 * 60 * 24));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 int seconds = epoch % 60;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 epoch = epoch / 60;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 int minutes = epoch % 60;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 int hours = epoch / 60;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 buf.append(DAYS[day_of_week]);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 buf.append(',');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 StringUtil.append2digits(buf, day_of_month);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 buf.append('-');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 buf.append(MONTHS[month]);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 buf.append('-');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 StringUtil.append2digits(buf, year/100);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 StringUtil.append2digits(buf, year%100);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 StringUtil.append2digits(buf, hours);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 buf.append(':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 StringUtil.append2digits(buf, minutes);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 buf.append(':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 StringUtil.append2digits(buf, seconds);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 buf.append(" GMT");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
161 private static final ThreadLocal<DateGenerator> __dateGenerator = new ThreadLocal<DateGenerator>()
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 @Override
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 protected DateGenerator initialValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 return new DateGenerator();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 * Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 */
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
174 private static String formatDate(long date)
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 return __dateGenerator.get().formatDate(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 */
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
183 private static void formatCookieDate(StringBuilder buf, long date)
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 __dateGenerator.get().formatCookieDate(buf,date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 */
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
192 private static String formatCookieDate(long date)
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 StringBuilder buf = new StringBuilder(28);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 formatCookieDate(buf, date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 return buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
198
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 private final static String __dateReceiveFmt[] =
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 "EEE, dd MMM yyyy HH:mm:ss zzz",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 "EEE, dd-MMM-yy HH:mm:ss",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 "EEE MMM dd HH:mm:ss yyyy",
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
204
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 "EEE, dd MMM yyyy HH:mm:ss", "EEE dd MMM yyyy HH:mm:ss zzz",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 "EEE dd MMM yyyy HH:mm:ss", "EEE MMM dd yyyy HH:mm:ss zzz", "EEE MMM dd yyyy HH:mm:ss",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 "EEE MMM-dd-yyyy HH:mm:ss zzz", "EEE MMM-dd-yyyy HH:mm:ss", "dd MMM yyyy HH:mm:ss zzz",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 "dd MMM yyyy HH:mm:ss", "dd-MMM-yy HH:mm:ss zzz", "dd-MMM-yy HH:mm:ss", "MMM dd HH:mm:ss yyyy zzz",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 "MMM dd HH:mm:ss yyyy", "EEE MMM dd HH:mm:ss yyyy zzz",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 "EEE, MMM dd HH:mm:ss yyyy zzz", "EEE, MMM dd HH:mm:ss yyyy", "EEE, dd-MMM-yy HH:mm:ss zzz",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 "EEE dd-MMM-yy HH:mm:ss zzz", "EEE dd-MMM-yy HH:mm:ss",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 private static class DateParser
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 {
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
216 final SimpleDateFormat _dateReceive[] = new SimpleDateFormat[__dateReceiveFmt.length];
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
217
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 long parse(final String dateVal)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 for (int i = 0; i < _dateReceive.length; i++)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 if (_dateReceive[i] == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 _dateReceive[i] = new SimpleDateFormat(__dateReceiveFmt[i], Locale.US);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 _dateReceive[i].setTimeZone(__GMT);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
227
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 Date date = (Date) _dateReceive[i].parseObject(dateVal);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 return date.getTime();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 catch (java.lang.Exception e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 // LOG.ignore(e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 if (dateVal.endsWith(" GMT"))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 final String val = dateVal.substring(0, dateVal.length() - 4);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
242
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 for (int i = 0; i < _dateReceive.length; i++)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 Date date = (Date) _dateReceive[i].parseObject(val);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 return date.getTime();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 catch (java.lang.Exception e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 // LOG.ignore(e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 return -1;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 private static final ThreadLocal<DateParser> __dateParser =new ThreadLocal<DateParser>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 @Override
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 protected DateParser initialValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 return new DateParser();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
269 private final static String __01Jan1970 = formatDate(0);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
270 private final static Buffer __01Jan1970_BUFFER = new ByteArrayBuffer(__01Jan1970);
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
271 private final static String __01Jan1970_COOKIE = formatCookieDate(0).trim();
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
272
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
273
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
274
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
275
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
276
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
277
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 private final ArrayList<Field> _fields = new ArrayList<Field>(20);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 private final HashMap<Buffer,Field> _names = new HashMap<Buffer,Field>(32);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
280 /*
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 private Buffer convertValue(String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
285 return new ByteArrayBuffer(value,StringUtil.__ISO_8859_1);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 catch (UnsupportedEncodingException e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 throw new RuntimeException(e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 }
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
292 */
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 * Get Collection of header names.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 public Collection<String> getFieldNamesCollection()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 final List<String> list = new ArrayList<String>(_fields.size());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
301
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
302 for (Field f : _fields)
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
303 {
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
304 if (f!=null)
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
305 list.add(BufferUtil.to8859_1_String(f._name));
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
306 }
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
307 return list;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 * Get enumeration of header _names. Returns an enumeration of strings representing the header
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 * _names for this request.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 public Enumeration<String> getFieldNames()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 final Enumeration<?> buffers = Collections.enumeration(_names.keySet());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 public String nextElement()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 return buffers.nextElement().toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 public boolean hasMoreElements()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 return buffers.hasMoreElements();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 public int size()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 return _fields.size();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 * Get a Field by index.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 * @return A Field value or null if the Field value has not been set
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 public Field getField(int i)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 return _fields.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
348
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 private Field getField(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 return _names.get(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
354
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 private Field getField(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 return _names.get(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
360
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 public boolean containsKey(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 return _names.containsKey(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
366
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 public boolean containsKey(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 return _names.containsKey(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
372
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 * @return the value of a field, or null if not found. For multiple fields of the same name,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 * only the first is returned.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 public String getStringField(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 return field==null?null:field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
384
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 * @return the value of a field, or null if not found. For multiple fields of the same name,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 * only the first is returned.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 public String getStringField(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 return field==null?null:field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
396
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 * Get multi headers
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 * @return Enumeration of the values, or null if no such header.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 public Collection<String> getValuesCollection(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 Field field = getField(name);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
407 if (field==null)
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
408 return null;
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
409
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
410 final List<String> list = new ArrayList<String>();
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
411
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
412 while(field!=null)
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
413 {
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
414 list.add(field.getValue());
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
415 field=field._next;
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
416 }
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
417 return list;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
419
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 * Get multi headers
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 * @return Enumeration of the values
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 public Enumeration<String> getValues(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 final Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 if (field == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 List<String> empty=Collections.emptyList();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 return Collections.enumeration(empty);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
435
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 Field f = field;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
439
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 public boolean hasMoreElements()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 return f != null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
444
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 public String nextElement() throws NoSuchElementException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 if (f == null) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 Field n = f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 f = f._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 return n.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
454
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 * Get multi headers
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 * @return Enumeration of the value Strings
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 public Enumeration<String> getValues(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 final Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 if (field == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 List<String> empty=Collections.emptyList();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 return Collections.enumeration(empty);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
470
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 Field f = field;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
474
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 public boolean hasMoreElements()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 return f != null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
479
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 public String nextElement() throws NoSuchElementException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 if (f == null) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 Field n = f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 f = f._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 return n.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
489
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 * Get multi field values with separator. The multiple values can be represented as separate
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 * headers of the same name, or by a single header using the separator(s), or a combination of
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 * both. Separators may be quoted.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 * @param separators String of separators.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 * @return Enumeration of the values, or null if no such header.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 public Enumeration<String> getValues(String name, final String separators)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 final Enumeration<String> e = getValues(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 if (e == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 return null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 QuotedStringTokenizer tok = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
508
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 public boolean hasMoreElements()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 if (tok != null && tok.hasMoreElements()) return true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 while (e.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 String value = e.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 tok = new QuotedStringTokenizer(value, separators, false, false);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 if (tok.hasMoreElements()) return true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 tok = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 return false;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 public String nextElement() throws NoSuchElementException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 if (!hasMoreElements()) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 String next = (String) tok.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 if (next != null) next = next.trim();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 return next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
531
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 * @param value the value of the field. If null the field is cleared.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 public void put(String name, String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
542 if (value==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 Buffer n = HttpHeaders.CACHE.lookup(name);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
547 put(n, value);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
550
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 * @param value the value of the field. If null the field is cleared.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 public void put(Buffer name, String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
560 /*
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 Buffer v = convertValue(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 put(n, v);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
564 */
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
565 remove(name);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
566 if (value == null)
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
567 return;
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
568
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
569 if (!(name instanceof BufferCache.CachedBuffer))
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
570 name = HttpHeaders.CACHE.lookup(name);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
571 int valueOrdinal = HttpHeaderValues.CACHE.getOrdinal(value);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
572
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
573 // new value;
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
574 Field field = new Field(name, value, valueOrdinal);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
575 _fields.add(field);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
576 _names.put(name, field);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
578
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 * @param value the value of the field. If null the field is cleared.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 public void put(Buffer name, Buffer value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
588 /*
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 if (value == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
592
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 if (!(name instanceof BufferCache.CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 if (!(value instanceof CachedBuffer))
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
596 value = HttpHeaderValues.CACHE.lookup(value).asImmutableBuffer();
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 // new value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 Field field = new Field(name, value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 _fields.add(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 _names.put(name, field);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
602 */
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
603 String s = value==null ? null : value.toString();
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
604 put(name,s);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
606
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 * Add to or set a field. If the field is allowed to have multiple values, add will add multiple
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 * headers of the same name.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 * @param value the value of the field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 * @exception IllegalArgumentException If the name is a single valued field and already has a
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 * value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 public void add(String name, String value) throws IllegalArgumentException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 if (value==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 return;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 Buffer n = HttpHeaders.CACHE.lookup(name);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
622 add(n, value);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
624
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 * Add to or set a field. If the field is allowed to have multiple values, add will add multiple
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 * headers of the same name.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 * @param value the value of the field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632 * @exception IllegalArgumentException If the name is a single valued field and already has a
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 * value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 */
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
635 public void add(Buffer name, String value) throws IllegalArgumentException
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 if (value == null) throw new IllegalArgumentException("null value");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
638
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 if (!(name instanceof CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 name=name.asImmutableBuffer();
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
642 /*
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 if (!(value instanceof CachedBuffer) && HttpHeaderValues.hasKnownValues(HttpHeaders.CACHE.getOrdinal(name)))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 value= HttpHeaderValues.CACHE.lookup(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 value=value.asImmutableBuffer();
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
646 */
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 Field field = _names.get(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 Field last = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 while (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 last = field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 field = field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
654
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 // create the field
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
656 int valueOrdinal = HttpHeaderValues.CACHE.getOrdinal(value);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
657 field = new Field(name, value, valueOrdinal);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 _fields.add(field);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
659
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 // look for chain to add too
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 if (last != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 last._next = field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 _names.put(name, field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 * Remove a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 * @param name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 public void remove(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 remove(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
677
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 * Remove a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
682 * @param name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 public void remove(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
686 if (!(name instanceof BufferCache.CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
687 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 Field field = _names.remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 while (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691 _fields.remove(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692 field = field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
695
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
696 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 * Get a header as an long value. Returns the value of an integer field or -1 if not found. The
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 * case of the field name is ignored.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 * @exception NumberFormatException If bad long found
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704 public long getLongField(String name) throws NumberFormatException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 return field==null?-1L:field.getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
709
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 * Get a header as an long value. Returns the value of an integer field or -1 if not found. The
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 * case of the field name is ignored.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 * @exception NumberFormatException If bad long found
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 public long getLongField(Buffer name) throws NumberFormatException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 return field==null?-1L:field.getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
723
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
724 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 * Get a header as a date value. Returns the value of a date field, or -1 if not found. The case
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
727 * of the field name is ignored.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
730 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 public long getDateField(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
732 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 if (field == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 return -1;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
736
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
737 String val = valueParameters(field._value, null);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 if (val == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 return -1;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
741 final long date = __dateParser.get().parse(val);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742 if (date==-1)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 throw new IllegalArgumentException("Cannot convert date: " + val);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 return date;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
746
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
747 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
748 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 * Sets the value of an long field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
750 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
751 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
753 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
754 public void putLongField(Buffer name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
756 // Buffer v = BufferUtil.toBuffer(value);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
757 String v = Long.toString(value);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
758 put(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
760
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
762 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
763 * Sets the value of an long field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
765 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
766 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
767 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
768 public void putLongField(String name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 Buffer n = HttpHeaders.CACHE.lookup(name);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
771 // Buffer v = BufferUtil.toBuffer(value);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
772 String v = Long.toString(value);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 put(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
775
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
776 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 * Sets the value of an long field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
780 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
781 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
782 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 public void addLongField(String name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
785 Buffer n = HttpHeaders.CACHE.lookup(name);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
786 // Buffer v = BufferUtil.toBuffer(value);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
787 String v = Long.toString(value);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 add(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
790
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
791 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
792 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
793 * Sets the value of an long field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
794 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
796 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
797 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
798 public void addLongField(Buffer name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
800 // Buffer v = BufferUtil.toBuffer(value);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
801 String v = Long.toString(value);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
802 add(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
803 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
804
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
805 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
806 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
807 * Sets the value of a date field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
808 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
809 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
810 * @param date the field date value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
811 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
812 public void putDateField(Buffer name, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
813 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
814 String d=formatDate(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
815 Buffer v = new ByteArrayBuffer(d);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
816 put(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
817 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
818
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
819 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
820 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
821 * Sets the value of a date field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
822 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
823 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
824 * @param date the field date value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
825 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
826 public void putDateField(String name, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
827 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
828 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
829 putDateField(n,date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
830 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
832 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
833 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
834 * Sets the value of a date field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
835 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
836 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
837 * @param date the field date value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
838 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
839 public void addDateField(String name, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
840 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
841 String d=formatDate(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
842 Buffer n = HttpHeaders.CACHE.lookup(name);
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
843 // Buffer v = new ByteArrayBuffer(d);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
844 add(n, d);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
845 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
846
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
847 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
848 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
849 * Format a set cookie value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
850 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
851 * @param cookie The cookie.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
852 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
853 public void addSetCookie(HttpCookie cookie)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
854 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
855 addSetCookie(
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
856 cookie.getName(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
857 cookie.getValue(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
858 cookie.getDomain(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
859 cookie.getPath(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
860 cookie.getMaxAge(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
861 cookie.getComment(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
862 cookie.isSecure(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
863 cookie.isHttpOnly(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
864 cookie.getVersion());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
865 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
866
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
867 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
868 * Format a set cookie value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
869 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
870 * @param name the name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
871 * @param value the value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
872 * @param domain the domain
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
873 * @param path the path
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
874 * @param maxAge the maximum age
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
875 * @param comment the comment (only present on versions > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
876 * @param isSecure true if secure cookie
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
877 * @param isHttpOnly true if for http only
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
878 * @param version version of cookie logic to use (0 == default behavior)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
879 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
880 public void addSetCookie(
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
881 final String name,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
882 final String value,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
883 final String domain,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
884 final String path,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
885 final long maxAge,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
886 final String comment,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
887 final boolean isSecure,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
888 final boolean isHttpOnly,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
889 int version)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
890 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
891 String delim=__COOKIE_DELIM;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
892
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
893 // Check arguments
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
894 if (name == null || name.length() == 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
895 throw new IllegalArgumentException("Bad cookie name");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
896
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
897 // Format value and params
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
898 StringBuilder buf = new StringBuilder(128);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
899 String name_value_params;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
900 QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
901 buf.append('=');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
902 String start=buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
903 boolean hasDomain = false;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
904 boolean hasPath = false;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
905
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
906 if (value != null && value.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
907 QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
908
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
909 if (comment != null && comment.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
910 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
911 buf.append(";Comment=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
912 QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
913 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
914
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
915 if (path != null && path.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
916 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
917 hasPath = true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
918 buf.append(";Path=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
919 if (path.trim().startsWith("\""))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
920 buf.append(path);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
921 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
922 QuotedStringTokenizer.quoteIfNeeded(buf,path,delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
923 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
924 if (domain != null && domain.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
925 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
926 hasDomain = true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
927 buf.append(";Domain=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
928 QuotedStringTokenizer.quoteIfNeeded(buf,domain.toLowerCase(Locale.ENGLISH),delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
929 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
930
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
931 if (maxAge >= 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
932 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
933 // Always add the expires param as some browsers still don't handle max-age
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
934 buf.append(";Expires=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
935 if (maxAge == 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
936 buf.append(__01Jan1970_COOKIE);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
937 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
938 formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
939
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
940 if (version >0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
941 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
942 buf.append(";Max-Age=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
943 buf.append(maxAge);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
944 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
945 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
946
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
947 if (isSecure)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
948 buf.append(";Secure");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
949 if (isHttpOnly)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
950 buf.append(";HttpOnly");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
951
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
952 name_value_params = buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
953
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
954 // remove existing set-cookie of same name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
955 Field field = getField(HttpHeaders.SET_COOKIE);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
956 Field last=null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
957 while (field!=null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
958 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
959 String val = (field._value == null ? null : field._value.toString());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
960 if (val!=null && val.startsWith(start))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
961 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
962 //existing cookie has same name, does it also match domain and path?
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
963 if (((!hasDomain && !val.contains("Domain")) || (hasDomain && val.contains("Domain="+domain))) &&
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
964 ((!hasPath && !val.contains("Path")) || (hasPath && val.contains("Path="+path))))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
965 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
966 _fields.remove(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
967 if (last==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
968 _names.put(HttpHeaders.SET_COOKIE_BUFFER,field._next);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
969 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
970 last._next=field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
971 break;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
972 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
973 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
974 last=field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
975 field=field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
976 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
977
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
978 add(HttpHeaders.SET_COOKIE_BUFFER, name_value_params);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
979
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
980 // Expire responses with set-cookie headers so they do not get cached.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
981 put(HttpHeaders.EXPIRES_BUFFER, __01Jan1970_BUFFER);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
982 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
983
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
984 @Override
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
985 public String toString()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
986 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
987 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
988 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
989 StringBuffer buffer = new StringBuffer();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
990 for (int i = 0; i < _fields.size(); i++)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
991 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
992 Field field = (Field) _fields.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
993 if (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
994 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
995 String tmp = field.getName();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
996 if (tmp != null) buffer.append(tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
997 buffer.append(": ");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
998 tmp = field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
999 if (tmp != null) buffer.append(tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1000 buffer.append("\r\n");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1001 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1002 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1003 buffer.append("\r\n");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1004 return buffer.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1005 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1006 catch (Exception e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1007 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1008 LOG.warn("",e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1009 return e.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1010 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1011 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1012
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1013 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1014 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1015 * Clear the header.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1016 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1017 public void clear()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1018 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1019 _fields.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1020 _names.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1021 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1022
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1023 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1024 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1025 * Add fields from another HttpFields instance. Single valued fields are replaced, while all
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1026 * others are added.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1027 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1028 * @param fields
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1029 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1030 public void add(HttpFields fields)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1031 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1032 if (fields == null) return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1033
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1034 Enumeration e = fields.getFieldNames();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1035 while (e.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1036 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1037 String name = (String) e.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1038 Enumeration values = fields.getValues(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1039 while (values.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1040 add(name, (String) values.nextElement());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1041 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1042 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1043
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1044 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1045 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1046 * Get field value parameters. Some field values can have parameters. This method separates the
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1047 * value from the parameters and optionally populates a map with the parameters. For example:
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1048 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1049 * <PRE>
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1050 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1051 * FieldName : Value ; param1=val1 ; param2=val2
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1052 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1053 * </PRE>
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1054 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1055 * @param value The Field value, possibly with parameteres.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1056 * @param parameters A map to populate with the parameters, or null
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1057 * @return The value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1058 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1059 public static String valueParameters(String value, Map<String,String> parameters)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1060 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1061 if (value == null) return null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1062
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1063 int i = value.indexOf(';');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1064 if (i < 0) return value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1065 if (parameters == null) return value.substring(0, i).trim();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1066
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1067 StringTokenizer tok1 = new QuotedStringTokenizer(value.substring(i), ";", false, true);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1068 while (tok1.hasMoreTokens())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1069 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1070 String token = tok1.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1071 StringTokenizer tok2 = new QuotedStringTokenizer(token, "= ");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1072 if (tok2.hasMoreTokens())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1073 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1074 String paramName = tok2.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1075 String paramVal = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1076 if (tok2.hasMoreTokens()) paramVal = tok2.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1077 parameters.put(paramName, paramVal);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1078 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1079 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1080
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1081 return value.substring(0, i).trim();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1082 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1083
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1084 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1085 private static final Float __zero = Float.valueOf("0.0");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1086
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1087 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1088 public static float getQuality(String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1089 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1090 if (value == null) return 0f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1091
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1092 if( value.indexOf(";") == -1 )
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1093 return 1f;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1094
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1095 Map params = new HashMap();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1096 valueParameters(value, params);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1097 String qs = (String) params.get("q");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1098 try {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1099 return Float.parseFloat(qs);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1100 } catch (NumberFormatException e) {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1101 return 1f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1102 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1103 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1104
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1105 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1106 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1107 * List values in quality order.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1108 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1109 * @param e Enumeration of values with quality parameters
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1110 * @return values in quality order.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1111 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1112 public static List qualityList(Enumeration e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1113 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1114 if (e == null || !e.hasMoreElements()) return Collections.EMPTY_LIST;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1115
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1116 Object list = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1117 Object qual = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1118
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1119 // Assume list will be well ordered and just add nonzero
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1120 while (e.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1121 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1122 String v = e.nextElement().toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1123 Float q = getQuality(v);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1124
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1125 if (q.floatValue() >= 0.001)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1126 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1127 list = LazyList.add(list, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1128 qual = LazyList.add(qual, q);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1129 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1130 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1131
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1132 List vl = LazyList.getList(list, false);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1133 if (vl.size() < 2) return vl;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1134
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1135 List ql = LazyList.getList(qual, false);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1136
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1137 // sort list with swaps
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1138 Float last = __zero;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1139 for (int i = vl.size(); i-- > 0;)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1140 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1141 Float q = (Float) ql.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1142 if (last.compareTo(q) > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1143 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1144 Object tmp = vl.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1145 vl.set(i, vl.get(i + 1));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1146 vl.set(i + 1, tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1147 ql.set(i, ql.get(i + 1));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1148 ql.set(i + 1, q);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1149 last = __zero;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1150 i = vl.size();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1151 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1152 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1153 last = q;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1154 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1155 ql.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1156 return vl;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1157 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1158
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1159
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1160 public static final class Field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1161 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1162 private final Buffer _name;
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1163 private final String _value;
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1164 private final int _valueOrdinal;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1165 private Field _next;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1166
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1167 private Field(Buffer name, String value, int valueOrdinal)
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1168 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1169 _name = name;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1170 _value = value;
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1171 _valueOrdinal = valueOrdinal;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1172 _next = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1173 }
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1174 /*
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1175 private Field(Buffer name, Buffer value)
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1176 {
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1177 this(name,value.toString(),HttpHeaderValues.CACHE.getOrdinal(value));
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1178 }
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1179 */
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1180 public void putTo(Buffer buffer) throws IOException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1181 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1182 int o=(_name instanceof CachedBuffer)?((CachedBuffer)_name).getOrdinal():-1;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1183 if (o>=0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1184 buffer.put(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1185 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1186 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1187 int s=_name.getIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1188 int e=_name.putIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1189 while (s<e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1190 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1191 byte b=_name.peek(s++);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1192 switch(b)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1193 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1194 case '\r':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1195 case '\n':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1196 case ':' :
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1197 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1198 default:
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1199 buffer.put(b);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1200 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1201 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1202 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1203
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1204 buffer.put((byte) ':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1205 buffer.put((byte) ' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1206
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1207 o = _valueOrdinal;
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1208 byte[] valueBytes = StringUtil.getBytes(_value);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1209 if (o>=0)
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1210 buffer.put(valueBytes);
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1211 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1212 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1213 for( byte b : valueBytes ) {
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1214 switch(b)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1215 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1216 case '\r':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1217 case '\n':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1218 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1219 default:
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1220 buffer.put(b);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1221 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1222 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1223 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1224
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1225 BufferUtil.putCRLF(buffer);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1226 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1227
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1228 private String getName()
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1229 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1230 return BufferUtil.to8859_1_String(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1231 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1232
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1233 public int getNameOrdinal()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1234 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1235 return HttpHeaders.CACHE.getOrdinal(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1236 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1237
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1238 public String getValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1239 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1240 return _value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1241 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1242
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1243 public int getValueOrdinal()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1244 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1245 return _valueOrdinal;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1246 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1247
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1248 public int getIntValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1249 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1250 return (int) getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1251 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1252
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1253 public long getLongValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1254 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1255 return BufferUtil.toLong(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1256 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1257
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
1258 @Override
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1259 public String toString()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1260 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1261 return ("[" + getName() + "=" + _value + (_next == null ? "" : "->") + "]");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1262 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1263 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1264 }