annotate src/org/eclipse/jetty/http/HttpFields.java @ 1019:f126d30e04a4

start replacing BufferCache with StringCache
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Oct 2016 03:33:42 -0600
parents fa6158f29c45
children 6be43ef1eb96
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);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 /* ------------------------------------------------------------ */
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 * Constructor.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 public HttpFields()
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
288
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 // TODO externalize this cache so it can be configurable
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 private static ConcurrentMap<String, Buffer> __cache = new ConcurrentHashMap<String, Buffer>();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 private static int __cacheSize = Integer.getInteger("org.eclipse.jetty.http.HttpFields.CACHE",2000);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292
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 private Buffer convertValue(String value)
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 Buffer buffer = __cache.get(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 if (buffer!=null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 return buffer;
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 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 buffer = new ByteArrayBuffer(value,StringUtil.__ISO_8859_1);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 if (__cacheSize>0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 if (__cache.size()>__cacheSize)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 __cache.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 Buffer b=__cache.putIfAbsent(value,buffer);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 if (b!=null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 buffer=b;
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
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 return buffer;
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 catch (UnsupportedEncodingException e)
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 throw new RuntimeException(e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 }
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
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 * Get Collection of header names.
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 Collection<String> getFieldNamesCollection()
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 final List<String> list = new ArrayList<String>(_fields.size());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
328
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
329 for (Field f : _fields)
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
330 {
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
331 if (f!=null)
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
332 list.add(BufferUtil.to8859_1_String(f._name));
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
333 }
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 855
diff changeset
334 return list;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 }
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 * 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
340 * _names for this request.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 public Enumeration<String> getFieldNames()
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 final Enumeration<?> buffers = Collections.enumeration(_names.keySet());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 public String nextElement()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 return buffers.nextElement().toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 }
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 public boolean hasMoreElements()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 return buffers.hasMoreElements();
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 };
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
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 public int size()
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 return _fields.size();
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
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 * Get a Field by index.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 * @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
369 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 public Field getField(int i)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 return _fields.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
375
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 private Field getField(String 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 return _names.get(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
381
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 private Field getField(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 return _names.get(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
387
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 public boolean containsKey(Buffer 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 return _names.containsKey(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
393
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 public boolean containsKey(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 return _names.containsKey(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
399
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 * @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
403 * only the first is returned.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 * @param name the case-insensitive field 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 public String getStringField(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 return field==null?null:field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
411
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 * @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
415 * only the first is returned.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 public String getStringField(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 return field==null?null:field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
423
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 * @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
427 * only the first is returned.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 public Buffer get(Buffer name)
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 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 return field==null?null:field._value;
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
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
436
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 * Get multi headers
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 * @return Enumeration of the values, or null if no such header.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 public Collection<String> getValuesCollection(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 Field field = getField(name);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
447 if (field==null)
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 return null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
449
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 final List<String> list = new ArrayList<String>();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
451
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
452 while(field!=null)
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
453 {
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 list.add(field.getValue());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 field=field._next;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
456 }
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
457 return list;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
459
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 /* -------------------------------------------------------------- */
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 * Get multi headers
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 * @return Enumeration of the values
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 * @param name the case-insensitive field name
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 public Enumeration<String> getValues(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 final Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 if (field == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 List<String> empty=Collections.emptyList();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 return Collections.enumeration(empty);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
475
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 Field f = field;
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 boolean hasMoreElements()
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 return f != null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
484
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 public String nextElement() throws NoSuchElementException
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 if (f == null) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 Field n = f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 f = f._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 return n.getValue();
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 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
494
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 * Get multi headers
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 * @return Enumeration of the value Strings
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 * @param name the case-insensitive field name
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 public Enumeration<String> getValues(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 final Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 if (field == null)
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 List<String> empty=Collections.emptyList();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 return Collections.enumeration(empty);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
510
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 Field f = field;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
514
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 public boolean hasMoreElements()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 return f != null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
519
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 public String nextElement() throws NoSuchElementException
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 if (f == null) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 Field n = f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 f = f._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 return n.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
529
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 * 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
533 * 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
534 * both. Separators may be quoted.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 * @param separators String of separators.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 * @return Enumeration of the values, or null if no such header.
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 Enumeration<String> getValues(String name, final String separators)
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 final Enumeration<String> e = getValues(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 if (e == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 return null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 QuotedStringTokenizer tok = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
548
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 public boolean hasMoreElements()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 if (tok != null && tok.hasMoreElements()) return true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 while (e.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 String value = e.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 tok = new QuotedStringTokenizer(value, separators, false, false);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 if (tok.hasMoreElements()) return true;
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 tok = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 return false;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 public String nextElement() throws NoSuchElementException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 if (!hasMoreElements()) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 String next = (String) tok.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 if (next != null) next = next.trim();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 return next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
571
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 * @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
579 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 public void put(String name, String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 if (value==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 else
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 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 Buffer v = convertValue(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 put(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
591
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 * @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
598 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 public void put(Buffer name, String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 Buffer v = convertValue(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 put(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
605
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 /* -------------------------------------------------------------- */
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 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 * @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
612 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 public void put(Buffer name, Buffer value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 if (value == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
618
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 if (!(name instanceof BufferCache.CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 if (!(value instanceof CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 value= HttpHeaderValues.CACHE.lookup(value).asImmutableBuffer();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 // new value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 Field field = new Field(name, value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 _fields.add(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 _names.put(name, field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
629
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 * @param list the List value of the field. If null the field is cleared.
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 public void put(String name, List<?> list)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 if (list == null || list.size() == 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 return;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 Buffer n = HttpHeaders.CACHE.lookup(name);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
645
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 Object v = list.get(0);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 if (v != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 put(n, HttpHeaderValues.CACHE.lookup(v.toString()));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 remove(n);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 if (list.size() > 1)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 java.util.Iterator<?> iter = list.iterator();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 iter.next();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656 while (iter.hasNext())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 v = iter.next();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 if (v != null) put(n, HttpHeaderValues.CACHE.lookup(v.toString()));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
663
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 /* -------------------------------------------------------------- */
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 * 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
667 * headers of the same name.
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 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 * @param value the value of the field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 * @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
672 * value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 public void add(String name, String value) throws IllegalArgumentException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 if (value==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
677 return;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 Buffer v = convertValue(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 add(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
682
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 * 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
686 * headers of the same name.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
687 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 * @param value the value of the field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 * @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
691 * value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 public void add(Buffer name, Buffer value) throws IllegalArgumentException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 if (value == null) throw new IllegalArgumentException("null value");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
696
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 if (!(name instanceof CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 name=name.asImmutableBuffer();
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 if (!(value instanceof CachedBuffer) && HttpHeaderValues.hasKnownValues(HttpHeaders.CACHE.getOrdinal(name)))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 value= HttpHeaderValues.CACHE.lookup(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 value=value.asImmutableBuffer();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 Field field = _names.get(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 Field last = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 while (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709 last = field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 field = field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
712
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 // create the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 field = new Field(name, value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 _fields.add(field);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
716
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 // look for chain to add too
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 if (last != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 last._next = field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 _names.put(name, field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723
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 * Remove a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
727 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 * @param name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
730 public void remove(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
732 remove(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
734
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
737 * Remove a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 * @param name
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 public void remove(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 if (!(name instanceof BufferCache.CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 Field field = _names.remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 while (field != null)
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 _fields.remove(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 field = field._next;
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
752
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 * 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
756 * case of the field name is ignored.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
757 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
758 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 * @exception NumberFormatException If bad long found
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
760 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761 public long getLongField(String name) throws NumberFormatException
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 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 return field==null?-1L:field.getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
765 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
766
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 * 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
770 * case of the field name is ignored.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
772 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 * @exception NumberFormatException If bad long found
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 public long getLongField(Buffer name) throws NumberFormatException
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 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 return field==null?-1L:field.getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
780
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
781 /* -------------------------------------------------------------- */
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 * 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
784 * of the field name is ignored.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
785 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
786 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
787 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 public long getDateField(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
790 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
791 if (field == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
792 return -1;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
793
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
794 String val = valueParameters(BufferUtil.to8859_1_String(field._value), null);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 if (val == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
796 return -1;
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 final long date = __dateParser.get().parse(val);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 if (date==-1)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
800 throw new IllegalArgumentException("Cannot convert date: " + val);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
801 return date;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
802 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
803
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
804 /* -------------------------------------------------------------- */
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 * Sets the value of an long field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
807 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
808 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
809 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
810 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
811 public void putLongField(Buffer name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
812 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
813 Buffer v = BufferUtil.toBuffer(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
814 put(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
815 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
816
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
817 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
818 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
819 * Sets the value of an long field.
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 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
822 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
823 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
824 public void putLongField(String name, long 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 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
827 Buffer v = BufferUtil.toBuffer(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
828 put(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
829 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
830
831
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 * Sets the value of an long field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
834 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
835 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
836 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
837 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
838 public void addLongField(String name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
839 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
840 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
841 Buffer v = BufferUtil.toBuffer(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
842 add(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
843 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
844
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
845 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
846 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
847 * Sets the value of an long field.
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 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
850 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
851 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
852 public void addLongField(Buffer name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
853 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
854 Buffer v = BufferUtil.toBuffer(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
855 add(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
856 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
857
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
858 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
859 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
860 * Sets the value of a date field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
861 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
862 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
863 * @param date the field date value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
864 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
865 public void putDateField(Buffer name, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
866 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
867 String d=formatDate(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
868 Buffer v = new ByteArrayBuffer(d);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
869 put(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
870 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
871
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
872 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
873 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
874 * Sets the value of a date field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
875 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
876 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
877 * @param date the field date value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
878 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
879 public void putDateField(String name, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
880 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
881 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
882 putDateField(n,date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
883 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
884
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
885 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
886 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
887 * Sets the value of a date field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
888 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
889 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
890 * @param date the field date value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
891 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
892 public void addDateField(String name, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
893 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
894 String d=formatDate(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
895 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
896 Buffer v = new ByteArrayBuffer(d);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
897 add(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
898 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
899
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
900 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
901 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
902 * Format a set cookie value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
903 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
904 * @param cookie The cookie.
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 public void addSetCookie(HttpCookie cookie)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
907 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
908 addSetCookie(
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
909 cookie.getName(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
910 cookie.getValue(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
911 cookie.getDomain(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
912 cookie.getPath(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
913 cookie.getMaxAge(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
914 cookie.getComment(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
915 cookie.isSecure(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
916 cookie.isHttpOnly(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
917 cookie.getVersion());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
918 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
919
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
920 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
921 * Format a set cookie value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
922 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
923 * @param name the name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
924 * @param value the value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
925 * @param domain the domain
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
926 * @param path the path
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
927 * @param maxAge the maximum age
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
928 * @param comment the comment (only present on versions > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
929 * @param isSecure true if secure cookie
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
930 * @param isHttpOnly true if for http only
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
931 * @param version version of cookie logic to use (0 == default behavior)
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 public void addSetCookie(
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
934 final String name,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
935 final String value,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
936 final String domain,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
937 final String path,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
938 final long maxAge,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
939 final String comment,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
940 final boolean isSecure,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
941 final boolean isHttpOnly,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
942 int version)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
943 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
944 String delim=__COOKIE_DELIM;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
945
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
946 // Check arguments
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
947 if (name == null || name.length() == 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
948 throw new IllegalArgumentException("Bad cookie name");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
949
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
950 // Format value and params
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
951 StringBuilder buf = new StringBuilder(128);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
952 String name_value_params;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
953 QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
954 buf.append('=');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
955 String start=buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
956 boolean hasDomain = false;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
957 boolean hasPath = false;
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 if (value != null && value.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
960 QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
961
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
962 if (comment != null && comment.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
963 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
964 buf.append(";Comment=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
965 QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
966 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
967
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
968 if (path != null && path.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
969 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
970 hasPath = true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
971 buf.append(";Path=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
972 if (path.trim().startsWith("\""))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
973 buf.append(path);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
974 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
975 QuotedStringTokenizer.quoteIfNeeded(buf,path,delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
976 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
977 if (domain != null && domain.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
978 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
979 hasDomain = true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
980 buf.append(";Domain=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
981 QuotedStringTokenizer.quoteIfNeeded(buf,domain.toLowerCase(Locale.ENGLISH),delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
982 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
983
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
984 if (maxAge >= 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
985 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
986 // 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
987 buf.append(";Expires=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
988 if (maxAge == 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
989 buf.append(__01Jan1970_COOKIE);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
990 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
991 formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
992
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
993 if (version >0)
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 buf.append(";Max-Age=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
996 buf.append(maxAge);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
997 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
998 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
999
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1000 if (isSecure)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1001 buf.append(";Secure");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1002 if (isHttpOnly)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1003 buf.append(";HttpOnly");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1004
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1005 name_value_params = buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1006
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1007 // remove existing set-cookie of same name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1008 Field field = getField(HttpHeaders.SET_COOKIE);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1009 Field last=null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1010 while (field!=null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1011 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1012 String val = (field._value == null ? null : field._value.toString());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1013 if (val!=null && val.startsWith(start))
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 //existing cookie has same name, does it also match domain and path?
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1016 if (((!hasDomain && !val.contains("Domain")) || (hasDomain && val.contains("Domain="+domain))) &&
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1017 ((!hasPath && !val.contains("Path")) || (hasPath && val.contains("Path="+path))))
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.remove(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1020 if (last==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1021 _names.put(HttpHeaders.SET_COOKIE_BUFFER,field._next);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1022 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1023 last._next=field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1024 break;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1025 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1026 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1027 last=field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1028 field=field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1029 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1030
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1031 add(HttpHeaders.SET_COOKIE_BUFFER, new ByteArrayBuffer(name_value_params));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1032
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1033 // Expire responses with set-cookie headers so they do not get cached.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1034 put(HttpHeaders.EXPIRES_BUFFER, __01Jan1970_BUFFER);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1035 }
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 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1038 public void putTo(Buffer buffer) throws IOException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1039 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1040 for (int i = 0; i < _fields.size(); i++)
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 Field field = _fields.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1043 if (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1044 field.putTo(buffer);
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 BufferUtil.putCRLF(buffer);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1047 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1048
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1049 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1050 public String toString()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1051 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1052 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1053 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1054 StringBuffer buffer = new StringBuffer();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1055 for (int i = 0; i < _fields.size(); i++)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1056 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1057 Field field = (Field) _fields.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1058 if (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1059 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1060 String tmp = field.getName();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1061 if (tmp != null) buffer.append(tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1062 buffer.append(": ");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1063 tmp = field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1064 if (tmp != null) buffer.append(tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1065 buffer.append("\r\n");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1066 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1067 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1068 buffer.append("\r\n");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1069 return buffer.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1070 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1071 catch (Exception e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1072 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1073 LOG.warn("",e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1074 return e.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1075 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1076 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1077
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1080 * Clear the header.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1081 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1082 public void clear()
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 _fields.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1085 _names.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1086 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1087
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1088 /* ------------------------------------------------------------ */
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 * 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
1091 * others are added.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1092 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1093 * @param fields
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1094 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1095 public void add(HttpFields fields)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1096 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1097 if (fields == null) return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1098
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1099 Enumeration e = fields.getFieldNames();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1100 while (e.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1101 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1102 String name = (String) e.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1103 Enumeration values = fields.getValues(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1104 while (values.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1105 add(name, (String) values.nextElement());
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1108
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1109 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1110 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1111 * 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
1112 * 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
1113 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1114 * <PRE>
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1115 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1116 * FieldName : Value ; param1=val1 ; param2=val2
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1117 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1118 * </PRE>
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1119 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1120 * @param value The Field value, possibly with parameteres.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1121 * @param parameters A map to populate with the parameters, or null
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1122 * @return The value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1123 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1124 public static String valueParameters(String value, Map<String,String> parameters)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1125 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1126 if (value == null) return null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1127
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1128 int i = value.indexOf(';');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1129 if (i < 0) return value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1130 if (parameters == null) return value.substring(0, i).trim();
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 StringTokenizer tok1 = new QuotedStringTokenizer(value.substring(i), ";", false, true);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1133 while (tok1.hasMoreTokens())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1134 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1135 String token = tok1.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1136 StringTokenizer tok2 = new QuotedStringTokenizer(token, "= ");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1137 if (tok2.hasMoreTokens())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1138 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1139 String paramName = tok2.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1140 String paramVal = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1141 if (tok2.hasMoreTokens()) paramVal = tok2.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1142 parameters.put(paramName, paramVal);
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1145
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1146 return value.substring(0, i).trim();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1147 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1148
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1149 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1150 private static final Float __zero = Float.valueOf("0.0");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1151
831
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 public static float getQuality(String value)
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 if (value == null) return 0f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1156
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1157 if( value.indexOf(";") == -1 )
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1158 return 1f;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1159
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1160 Map params = new HashMap();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1161 valueParameters(value, params);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1162 String qs = (String) params.get("q");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1163 try {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1164 return Float.parseFloat(qs);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1165 } catch (NumberFormatException e) {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1166 return 1f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1167 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1168 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1169
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1170 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1171 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1172 * List values in quality order.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1173 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1174 * @param e Enumeration of values with quality parameters
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1175 * @return values in quality order.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1176 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1177 public static List qualityList(Enumeration e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1178 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1179 if (e == null || !e.hasMoreElements()) return Collections.EMPTY_LIST;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1180
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1181 Object list = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1182 Object qual = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1183
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1184 // Assume list will be well ordered and just add nonzero
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1185 while (e.hasMoreElements())
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 String v = e.nextElement().toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1188 Float q = getQuality(v);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1189
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1190 if (q.floatValue() >= 0.001)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1191 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1192 list = LazyList.add(list, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1193 qual = LazyList.add(qual, q);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1194 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1195 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1196
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1197 List vl = LazyList.getList(list, false);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1198 if (vl.size() < 2) return vl;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1199
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1200 List ql = LazyList.getList(qual, false);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1201
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1202 // sort list with swaps
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1203 Float last = __zero;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1204 for (int i = vl.size(); i-- > 0;)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1205 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1206 Float q = (Float) ql.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1207 if (last.compareTo(q) > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1208 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1209 Object tmp = vl.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1210 vl.set(i, vl.get(i + 1));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1211 vl.set(i + 1, tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1212 ql.set(i, ql.get(i + 1));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1213 ql.set(i + 1, q);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1214 last = __zero;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1215 i = vl.size();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1216 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1217 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1218 last = q;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1219 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1220 ql.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1221 return vl;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1222 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1223
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1224 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1225 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1226 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1227 public static final class Field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1228 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1229 private Buffer _name;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1230 private Buffer _value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1231 private Field _next;
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 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1234 private Field(Buffer name, Buffer value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1235 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1236 _name = name;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1237 _value = value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1238 _next = null;
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
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1241 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1242 public void putTo(Buffer buffer) throws IOException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1243 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1244 int o=(_name instanceof CachedBuffer)?((CachedBuffer)_name).getOrdinal():-1;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1245 if (o>=0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1246 buffer.put(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1247 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1248 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1249 int s=_name.getIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1250 int e=_name.putIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1251 while (s<e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1252 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1253 byte b=_name.peek(s++);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1254 switch(b)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1255 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1256 case '\r':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1257 case '\n':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1258 case ':' :
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1259 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1260 default:
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1261 buffer.put(b);
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 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1264 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1265
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1266 buffer.put((byte) ':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1267 buffer.put((byte) ' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1268
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1269 o=(_value instanceof CachedBuffer)?((CachedBuffer)_value).getOrdinal():-1;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1270 if (o>=0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1271 buffer.put(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1272 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1273 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1274 int s=_value.getIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1275 int e=_value.putIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1276 while (s<e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1277 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1278 byte b=_value.peek(s++);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1279 switch(b)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1280 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1281 case '\r':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1282 case '\n':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1283 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1284 default:
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1285 buffer.put(b);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1286 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1287 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1288 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1289
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1290 BufferUtil.putCRLF(buffer);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1291 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1292
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1293 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1294 public String getName()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1295 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1296 return BufferUtil.to8859_1_String(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1297 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1298
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1299 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1300 Buffer getNameBuffer()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1301 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1302 return _name;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1303 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1304
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1305 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1306 public int getNameOrdinal()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1307 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1308 return HttpHeaders.CACHE.getOrdinal(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1309 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1310
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1311 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1312 public String getValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1313 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1314 return BufferUtil.to8859_1_String(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1315 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1316
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1317 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1318 public Buffer getValueBuffer()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1319 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1320 return _value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1321 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1322
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1323 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1324 public int getValueOrdinal()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1325 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1326 return HttpHeaderValues.CACHE.getOrdinal(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1327 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1328
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1329 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1330 public int getIntValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1331 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1332 return (int) getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1333 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1334
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1335 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1336 public long getLongValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1337 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1338 return BufferUtil.toLong(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1339 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1340
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1341 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1342 public String toString()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1343 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1344 return ("[" + getName() + "=" + _value + (_next == null ? "" : "->") + "]");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1345 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1346 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1347 }