annotate src/org/eclipse/jetty/http/HttpFields.java @ 862:2bb375e94f64

simplify jetty.util.IO
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 02 Oct 2016 05:17:11 -0600
parents fa6158f29c45
children f126d30e04a4
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 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 public class HttpFields
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
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 public static final String __COOKIE_DELIM="\"\\\n\r\t\f\b%+ ;=";
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 public static final TimeZone __GMT = TimeZone.getTimeZone("GMT");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 private static final String[] DAYS =
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 { "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 private static final String[] MONTHS =
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 { "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
75
831
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 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 private static class DateGenerator
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 private final StringBuilder buf = new StringBuilder(32);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 private final GregorianCalendar gc = new GregorianCalendar(__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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 * Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 public String formatDate(long 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 buf.setLength(0);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 gc.setTimeInMillis(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 int day_of_week = gc.get(Calendar.DAY_OF_WEEK);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 int day_of_month = gc.get(Calendar.DAY_OF_MONTH);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 int month = gc.get(Calendar.MONTH);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 int year = gc.get(Calendar.YEAR);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 int century = year / 100;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 year = year % 100;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 int hours = gc.get(Calendar.HOUR_OF_DAY);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 int minutes = gc.get(Calendar.MINUTE);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 int seconds = gc.get(Calendar.SECOND);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 buf.append(DAYS[day_of_week]);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 buf.append(',');
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 StringUtil.append2digits(buf, day_of_month);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 buf.append(MONTHS[month]);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 StringUtil.append2digits(buf, century);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 StringUtil.append2digits(buf, year);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 StringUtil.append2digits(buf, hours);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 buf.append(':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 StringUtil.append2digits(buf, minutes);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 buf.append(':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 StringUtil.append2digits(buf, seconds);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 buf.append(" GMT");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 return buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 * Format "EEE, dd-MMM-yy HH:mm:ss 'GMT'" for cookies
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 public void formatCookieDate(StringBuilder buf, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 gc.setTimeInMillis(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 int day_of_week = gc.get(Calendar.DAY_OF_WEEK);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 int day_of_month = gc.get(Calendar.DAY_OF_MONTH);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133 int month = gc.get(Calendar.MONTH);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 int year = gc.get(Calendar.YEAR);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 year = year % 10000;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 int epoch = (int) ((date / 1000) % (60 * 60 * 24));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 int seconds = epoch % 60;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 epoch = epoch / 60;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 int minutes = epoch % 60;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 int hours = epoch / 60;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 buf.append(DAYS[day_of_week]);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 buf.append(',');
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 StringUtil.append2digits(buf, day_of_month);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 buf.append('-');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 buf.append(MONTHS[month]);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 buf.append('-');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 StringUtil.append2digits(buf, year/100);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 StringUtil.append2digits(buf, year%100);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 buf.append(' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 StringUtil.append2digits(buf, hours);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 buf.append(':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 StringUtil.append2digits(buf, minutes);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 buf.append(':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 StringUtil.append2digits(buf, seconds);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 buf.append(" GMT");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 private static final ThreadLocal<DateGenerator> __dateGenerator =new ThreadLocal<DateGenerator>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 @Override
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 protected DateGenerator initialValue()
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 return new DateGenerator();
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 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 /* ------------------------------------------------------------ */
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 * Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 public static String formatDate(long date)
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 return __dateGenerator.get().formatDate(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 /* ------------------------------------------------------------ */
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 * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
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 public static void formatCookieDate(StringBuilder buf, long date)
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 __dateGenerator.get().formatCookieDate(buf,date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 /* ------------------------------------------------------------ */
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 * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 public static String formatCookieDate(long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 StringBuilder buf = new StringBuilder(28);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 formatCookieDate(buf, date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 return buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 private final static String __dateReceiveFmt[] =
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 "EEE, dd MMM yyyy HH:mm:ss zzz",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 "EEE, dd-MMM-yy HH:mm:ss",
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 "EEE MMM dd HH:mm:ss yyyy",
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
209
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 "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
211 "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
212 "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
213 "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
214 "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
215 "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
216 "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
217 };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
218
831
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 private static class DateParser
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 final SimpleDateFormat _dateReceive[]= new SimpleDateFormat[__dateReceiveFmt.length];
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 long parse(final String dateVal)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 for (int i = 0; i < _dateReceive.length; i++)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 if (_dateReceive[i] == null)
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 _dateReceive[i] = new SimpleDateFormat(__dateReceiveFmt[i], Locale.US);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 _dateReceive[i].setTimeZone(__GMT);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
233
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 Date date = (Date) _dateReceive[i].parseObject(dateVal);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 return date.getTime();
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 catch (java.lang.Exception e)
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 // LOG.ignore(e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 }
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 if (dateVal.endsWith(" GMT"))
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 final String val = dateVal.substring(0, dateVal.length() - 4);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
248
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 for (int i = 0; i < _dateReceive.length; i++)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 Date date = (Date) _dateReceive[i].parseObject(val);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 return date.getTime();
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 catch (java.lang.Exception e)
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 // LOG.ignore(e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 }
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 return -1;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
265
831
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 public static long parseDate(String date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 return __dateParser.get().parse(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
271
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 private static final ThreadLocal<DateParser> __dateParser =new ThreadLocal<DateParser>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 @Override
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 protected DateParser initialValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 return new DateParser();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
281
831
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 public final static String __01Jan1970=formatDate(0);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 public final static Buffer __01Jan1970_BUFFER=new ByteArrayBuffer(__01Jan1970);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 public final static String __01Jan1970_COOKIE = formatCookieDate(0).trim();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
286
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 private final ArrayList<Field> _fields = new ArrayList<Field>(20);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 private final HashMap<Buffer,Field> _names = new HashMap<Buffer,Field>(32);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 /* ------------------------------------------------------------ */
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 * Constructor.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 public HttpFields()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
298
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 // TODO externalize this cache so it can be configurable
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 private static ConcurrentMap<String, Buffer> __cache = new ConcurrentHashMap<String, Buffer>();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 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
302
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 private Buffer convertValue(String value)
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 Buffer buffer = __cache.get(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 if (buffer!=null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 return buffer;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 try
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 buffer = new ByteArrayBuffer(value,StringUtil.__ISO_8859_1);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 if (__cacheSize>0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 if (__cache.size()>__cacheSize)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 __cache.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 Buffer b=__cache.putIfAbsent(value,buffer);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 if (b!=null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 buffer=b;
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 return buffer;
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 catch (UnsupportedEncodingException e)
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 throw new RuntimeException(e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 * Get Collection of header names.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 public Collection<String> getFieldNamesCollection()
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 final List<String> list = new ArrayList<String>(_fields.size());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
338
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
339 for (Field f : _fields)
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
340 {
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 if (f!=null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 list.add(BufferUtil.to8859_1_String(f._name));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
343 }
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
344 return list;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 /* -------------------------------------------------------------- */
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 * 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
350 * _names for this request.
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 Enumeration<String> getFieldNames()
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 final Enumeration<?> buffers = Collections.enumeration(_names.keySet());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 return new Enumeration<String>()
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 public String nextElement()
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 return buffers.nextElement().toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 public boolean hasMoreElements()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 return buffers.hasMoreElements();
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 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368
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 public int size()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 return _fields.size();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 /* ------------------------------------------------------------ */
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 * Get a Field by index.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 * @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
379 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 public Field getField(int i)
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 return _fields.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
385
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 private Field getField(String name)
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 return _names.get(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
391
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 private Field getField(Buffer name)
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 return _names.get(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
397
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 public boolean containsKey(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 return _names.containsKey(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
403
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 public boolean containsKey(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 return _names.containsKey(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
409
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 * @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
413 * only the first is returned.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
415 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 public String getStringField(String 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 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 return field==null?null:field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
421
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 * @return 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
425 * only the first is returned.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 public String getStringField(Buffer 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 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 return field==null?null:field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
433
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 * @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
437 * only the first is returned.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 public Buffer get(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 return field==null?null:field._value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
445
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
446
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 * Get multi headers
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 * @return Enumeration of the values, or null if no such header.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 public Collection<String> getValuesCollection(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 Field field = getField(name);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
457 if (field==null)
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 return null;
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 final List<String> list = new ArrayList<String>();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
461
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
462 while(field!=null)
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
463 {
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 list.add(field.getValue());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 field=field._next;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
466 }
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
467 return list;
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
469
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 /* -------------------------------------------------------------- */
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 * Get multi headers
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 * @return Enumeration of the values
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 public Enumeration<String> getValues(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 final Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 if (field == null)
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 List<String> empty=Collections.emptyList();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 return Collections.enumeration(empty);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
485
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 Field f = field;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
489
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 public boolean hasMoreElements()
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 return f != null;
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 public String nextElement() throws NoSuchElementException
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 if (f == null) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 Field n = f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 f = f._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 return n.getValue();
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 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
504
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 /* -------------------------------------------------------------- */
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 * Get multi headers
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 * @return Enumeration of the value Strings
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 public Enumeration<String> getValues(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 final Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 if (field == null)
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 List<String> empty=Collections.emptyList();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 return Collections.enumeration(empty);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
520
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 Field f = field;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
524
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 public boolean hasMoreElements()
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 return f != null;
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 public String nextElement() throws NoSuchElementException
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 if (f == null) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 Field n = f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 f = f._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 return n.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 };
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
539
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 /* -------------------------------------------------------------- */
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 * 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
543 * 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
544 * both. Separators may be quoted.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 * @param separators String of separators.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 * @return Enumeration of the values, or null if no such header.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 public Enumeration<String> getValues(String name, final String separators)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 final Enumeration<String> e = getValues(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 if (e == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 return null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 return new Enumeration<String>()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 QuotedStringTokenizer tok = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
558
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 public boolean hasMoreElements()
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 if (tok != null && tok.hasMoreElements()) return true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 while (e.hasMoreElements())
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 String value = e.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 tok = new QuotedStringTokenizer(value, separators, false, false);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 if (tok.hasMoreElements()) return true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 tok = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 return false;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 public String nextElement() throws NoSuchElementException
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 if (!hasMoreElements()) throw new NoSuchElementException();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 String next = (String) tok.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 if (next != null) next = next.trim();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 return next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
581
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 * @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
589 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 public void put(String name, String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 if (value==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 else
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 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 Buffer v = convertValue(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 put(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
601
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 * @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
608 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 public void put(Buffer name, String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 Buffer v = convertValue(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 put(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
615
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 * Set a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 * @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
622 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 public void put(Buffer name, Buffer value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 if (value == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
628
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 if (!(name instanceof BufferCache.CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 if (!(value instanceof CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632 value= HttpHeaderValues.CACHE.lookup(value).asImmutableBuffer();
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 // new value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 Field field = new Field(name, value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 _fields.add(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 _names.put(name, field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
639
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 * Set a field.
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 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 * @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
646 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 public void put(String name, List<?> list)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 if (list == null || list.size() == 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 return;
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 Buffer n = HttpHeaders.CACHE.lookup(name);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
655
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656 Object v = list.get(0);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 if (v != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 put(n, HttpHeaderValues.CACHE.lookup(v.toString()));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 remove(n);
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 if (list.size() > 1)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 java.util.Iterator<?> iter = list.iterator();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 iter.next();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 while (iter.hasNext())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 v = iter.next();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 if (v != null) put(n, HttpHeaderValues.CACHE.lookup(v.toString()));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
673
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 * 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
677 * headers of the same name.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 * @param value the value of the field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 * @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
682 * value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 public void add(String name, String value) throws IllegalArgumentException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
686 if (value==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
687 return;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689 Buffer v = convertValue(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 add(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
692
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 * 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
696 * headers of the same name.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 * @param name the name of the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 * @param value the value of the field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 * @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
701 * value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 public void add(Buffer name, Buffer value) throws IllegalArgumentException
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 if (value == null) throw new IllegalArgumentException("null value");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
706
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
707 if (!(name instanceof CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709 name=name.asImmutableBuffer();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 if (!(value instanceof CachedBuffer) && HttpHeaderValues.hasKnownValues(HttpHeaders.CACHE.getOrdinal(name)))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 value= HttpHeaderValues.CACHE.lookup(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 value=value.asImmutableBuffer();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 Field field = _names.get(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 Field last = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 while (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719 last = field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720 field = field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
722
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 // create the field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
724 field = new Field(name, value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 _fields.add(field);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
726
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
727 // look for chain to add too
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 if (last != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 last._next = field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
730 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 _names.put(name, field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
732 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 /* ------------------------------------------------------------ */
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 * Remove a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
737 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 * @param name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 public void remove(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
741 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742 remove(HttpHeaders.CACHE.lookup(name));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
744
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
747 * Remove a field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
748 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 * @param name
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 public void remove(Buffer name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
753 if (!(name instanceof BufferCache.CachedBuffer))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
754 name = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 Field field = _names.remove(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
756 while (field != null)
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 _fields.remove(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 field = field._next;
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
762
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
763 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
765 * 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
766 * case of the field name is ignored.
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 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 * @exception NumberFormatException If bad long found
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 public long getLongField(String name) throws NumberFormatException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
772 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 return field==null?-1L:field.getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
776
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779 * 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
780 * case of the field name is ignored.
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 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 * @exception NumberFormatException If bad long found
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
785 public long getLongField(Buffer name) throws NumberFormatException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
786 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
787 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 return field==null?-1L:field.getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
790
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
791 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
792 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
793 * 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
794 * of the field name is ignored.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
796 * @param name the case-insensitive field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
797 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
798 public long getDateField(String name)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
800 Field field = getField(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
801 if (field == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
802 return -1;
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 String val = valueParameters(BufferUtil.to8859_1_String(field._value), null);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
805 if (val == null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
806 return -1;
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 final long date = __dateParser.get().parse(val);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
809 if (date==-1)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
810 throw new IllegalArgumentException("Cannot convert date: " + val);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
811 return date;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
812 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
813
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
814 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
815 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
816 * Sets the value of an long field.
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 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
819 * @param value the field long value
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 public void putLongField(Buffer name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
822 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
823 Buffer v = BufferUtil.toBuffer(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
824 put(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
825 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
826
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
827 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
828 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
829 * Sets the value of an long field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
830 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
831 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
832 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
833 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
834 public void putLongField(String name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
835 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
836 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
837 Buffer v = BufferUtil.toBuffer(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
838 put(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
839 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
840
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
841 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
842 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
843 * Sets the value of an long field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
844 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
845 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
846 * @param value the field long value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
847 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
848 public void addLongField(String name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
849 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
850 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
851 Buffer v = BufferUtil.toBuffer(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
852 add(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
853 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
854
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
855 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
856 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
857 * Sets the value of an long field.
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 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
860 * @param value the field long value
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 public void addLongField(Buffer name, long value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
863 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
864 Buffer v = BufferUtil.toBuffer(value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
865 add(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
866 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
867
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
868 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
869 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
870 * Sets the value of a date field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
871 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
872 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
873 * @param date the field date value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
874 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
875 public void putDateField(Buffer name, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
876 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
877 String d=formatDate(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
878 Buffer v = new ByteArrayBuffer(d);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
879 put(name, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
880 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
881
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
882 /* -------------------------------------------------------------- */
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 * Sets the value of a date field.
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 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
887 * @param date the field date value
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 public void putDateField(String name, long date)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
890 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
891 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
892 putDateField(n,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
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
895 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
896 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
897 * Sets the value of a date field.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
898 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
899 * @param name the field name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
900 * @param date the field date value
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 public void addDateField(String name, long date)
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 String d=formatDate(date);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
905 Buffer n = HttpHeaders.CACHE.lookup(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
906 Buffer v = new ByteArrayBuffer(d);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
907 add(n, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
908 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
909
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
910 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
911 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
912 * Format a set cookie value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
913 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
914 * @param cookie The cookie.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
915 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
916 public void addSetCookie(HttpCookie cookie)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
917 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
918 addSetCookie(
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
919 cookie.getName(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
920 cookie.getValue(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
921 cookie.getDomain(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
922 cookie.getPath(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
923 cookie.getMaxAge(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
924 cookie.getComment(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
925 cookie.isSecure(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
926 cookie.isHttpOnly(),
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
927 cookie.getVersion());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
928 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
929
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
930 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
931 * Format a set cookie value
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 * @param name the name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
934 * @param value the value
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
935 * @param domain the domain
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
936 * @param path the path
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
937 * @param maxAge the maximum age
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
938 * @param comment the comment (only present on versions > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
939 * @param isSecure true if secure cookie
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
940 * @param isHttpOnly true if for http only
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
941 * @param version version of cookie logic to use (0 == default behavior)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
942 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
943 public void addSetCookie(
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
944 final String name,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
945 final String value,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
946 final String domain,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
947 final String path,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
948 final long maxAge,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
949 final String comment,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
950 final boolean isSecure,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
951 final boolean isHttpOnly,
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
952 int version)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
953 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
954 String delim=__COOKIE_DELIM;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
955
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
956 // Check arguments
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
957 if (name == null || name.length() == 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
958 throw new IllegalArgumentException("Bad cookie name");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
959
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
960 // Format value and params
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
961 StringBuilder buf = new StringBuilder(128);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
962 String name_value_params;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
963 QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
964 buf.append('=');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
965 String start=buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
966 boolean hasDomain = false;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
967 boolean hasPath = false;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
968
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
969 if (value != null && value.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
970 QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
971
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
972 if (comment != null && comment.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
973 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
974 buf.append(";Comment=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
975 QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
976 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
977
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
978 if (path != null && path.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
979 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
980 hasPath = true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
981 buf.append(";Path=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
982 if (path.trim().startsWith("\""))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
983 buf.append(path);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
984 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
985 QuotedStringTokenizer.quoteIfNeeded(buf,path,delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
986 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
987 if (domain != null && domain.length() > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
988 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
989 hasDomain = true;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
990 buf.append(";Domain=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
991 QuotedStringTokenizer.quoteIfNeeded(buf,domain.toLowerCase(Locale.ENGLISH),delim);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
992 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
993
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
994 if (maxAge >= 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
995 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
996 // 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
997 buf.append(";Expires=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
998 if (maxAge == 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
999 buf.append(__01Jan1970_COOKIE);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1000 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1001 formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1002
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1003 if (version >0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1004 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1005 buf.append(";Max-Age=");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1006 buf.append(maxAge);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1007 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1008 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1009
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1010 if (isSecure)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1011 buf.append(";Secure");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1012 if (isHttpOnly)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1013 buf.append(";HttpOnly");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1014
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1015 name_value_params = buf.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1016
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1017 // remove existing set-cookie of same name
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1018 Field field = getField(HttpHeaders.SET_COOKIE);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1019 Field last=null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1020 while (field!=null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1021 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1022 String val = (field._value == null ? null : field._value.toString());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1023 if (val!=null && val.startsWith(start))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1024 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1025 //existing cookie has same name, does it also match domain and path?
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1026 if (((!hasDomain && !val.contains("Domain")) || (hasDomain && val.contains("Domain="+domain))) &&
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1027 ((!hasPath && !val.contains("Path")) || (hasPath && val.contains("Path="+path))))
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1028 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1029 _fields.remove(field);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1030 if (last==null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1031 _names.put(HttpHeaders.SET_COOKIE_BUFFER,field._next);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1032 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1033 last._next=field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1034 break;
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 last=field;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1038 field=field._next;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1039 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1040
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1041 add(HttpHeaders.SET_COOKIE_BUFFER, new ByteArrayBuffer(name_value_params));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1042
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1043 // Expire responses with set-cookie headers so they do not get cached.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1044 put(HttpHeaders.EXPIRES_BUFFER, __01Jan1970_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
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1047 /* -------------------------------------------------------------- */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1048 public void putTo(Buffer buffer) throws IOException
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 for (int i = 0; i < _fields.size(); i++)
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 Field field = _fields.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1053 if (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1054 field.putTo(buffer);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1055 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1056 BufferUtil.putCRLF(buffer);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1057 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1058
831
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 public String toString()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1061 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1062 try
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1063 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1064 StringBuffer buffer = new StringBuffer();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1065 for (int i = 0; i < _fields.size(); i++)
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 Field field = (Field) _fields.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1068 if (field != null)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1069 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1070 String tmp = field.getName();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1071 if (tmp != null) buffer.append(tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1072 buffer.append(": ");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1073 tmp = field.getValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1074 if (tmp != null) buffer.append(tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1075 buffer.append("\r\n");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1076 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1077 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1078 buffer.append("\r\n");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1079 return buffer.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1080 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1081 catch (Exception e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1082 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1083 LOG.warn("",e);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1084 return e.toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1085 }
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 * Clear the header.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1091 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1092 public void clear()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1093 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1094 _fields.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1095 _names.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1096 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1097
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1098 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1099 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1100 * 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
1101 * others are added.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1102 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1103 * @param fields
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1104 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1105 public void add(HttpFields fields)
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 if (fields == null) return;
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 Enumeration e = fields.getFieldNames();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1110 while (e.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1111 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1112 String name = (String) e.nextElement();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1113 Enumeration values = fields.getValues(name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1114 while (values.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1115 add(name, (String) values.nextElement());
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1116 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1117 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1118
831
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 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1121 * 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
1122 * 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
1123 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1124 * <PRE>
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 * FieldName : Value ; param1=val1 ; param2=val2
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 * </PRE>
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1129 *
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1130 * @param value The Field value, possibly with parameteres.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1131 * @param parameters A map to populate with the parameters, or null
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1132 * @return The value.
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1133 */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1134 public static String valueParameters(String value, Map<String,String> parameters)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1135 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1136 if (value == null) return null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1137
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1138 int i = value.indexOf(';');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1139 if (i < 0) return value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1140 if (parameters == null) return value.substring(0, i).trim();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1141
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1142 StringTokenizer tok1 = new QuotedStringTokenizer(value.substring(i), ";", false, true);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1143 while (tok1.hasMoreTokens())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1144 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1145 String token = tok1.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1146 StringTokenizer tok2 = new QuotedStringTokenizer(token, "= ");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1147 if (tok2.hasMoreTokens())
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 String paramName = tok2.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1150 String paramVal = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1151 if (tok2.hasMoreTokens()) paramVal = tok2.nextToken();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1152 parameters.put(paramName, paramVal);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1153 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1154 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1155
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1156 return value.substring(0, i).trim();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1157 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1158
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1159 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1160 private static final Float __zero = Float.valueOf("0.0");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1161
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1162 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1163 public static float getQuality(String value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1164 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1165 if (value == null) return 0f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1166
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1167 if( value.indexOf(";") == -1 )
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1168 return 1f;
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 Map params = new HashMap();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1171 valueParameters(value, params);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1172 String qs = (String) params.get("q");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1173 try {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1174 return Float.parseFloat(qs);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1175 } catch (NumberFormatException e) {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1176 return 1f;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1177 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1178 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1179
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1180 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1181 /**
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1182 * List values in quality order.
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 * @param e Enumeration of values with quality parameters
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1185 * @return values in quality order.
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 public static List qualityList(Enumeration e)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1188 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1189 if (e == null || !e.hasMoreElements()) return Collections.EMPTY_LIST;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1190
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1191 Object list = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1192 Object qual = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1193
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1194 // Assume list will be well ordered and just add nonzero
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1195 while (e.hasMoreElements())
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1196 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1197 String v = e.nextElement().toString();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1198 Float q = getQuality(v);
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 if (q.floatValue() >= 0.001)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1201 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1202 list = LazyList.add(list, v);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1203 qual = LazyList.add(qual, q);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1204 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1205 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1206
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1207 List vl = LazyList.getList(list, false);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1208 if (vl.size() < 2) return vl;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1209
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1210 List ql = LazyList.getList(qual, false);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1211
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1212 // sort list with swaps
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1213 Float last = __zero;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1214 for (int i = vl.size(); i-- > 0;)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1215 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1216 Float q = (Float) ql.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1217 if (last.compareTo(q) > 0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1218 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1219 Object tmp = vl.get(i);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1220 vl.set(i, vl.get(i + 1));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1221 vl.set(i + 1, tmp);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1222 ql.set(i, ql.get(i + 1));
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1223 ql.set(i + 1, q);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1224 last = __zero;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1225 i = vl.size();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1226 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1227 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1228 last = q;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1229 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1230 ql.clear();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1231 return vl;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1232 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1233
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1234 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1235 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1236 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1237 public static final class Field
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1238 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1239 private Buffer _name;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1240 private Buffer _value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1241 private Field _next;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1242
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1243 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1244 private Field(Buffer name, Buffer value)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1245 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1246 _name = name;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1247 _value = value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1248 _next = null;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1249 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1250
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1251 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1252 public void putTo(Buffer buffer) throws IOException
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1253 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1254 int o=(_name instanceof CachedBuffer)?((CachedBuffer)_name).getOrdinal():-1;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1255 if (o>=0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1256 buffer.put(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1257 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1258 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1259 int s=_name.getIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1260 int e=_name.putIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1261 while (s<e)
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 byte b=_name.peek(s++);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1264 switch(b)
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 case '\r':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1267 case '\n':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1268 case ':' :
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1269 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1270 default:
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1271 buffer.put(b);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1272 }
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 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1275
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1276 buffer.put((byte) ':');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1277 buffer.put((byte) ' ');
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1278
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1279 o=(_value instanceof CachedBuffer)?((CachedBuffer)_value).getOrdinal():-1;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1280 if (o>=0)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1281 buffer.put(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1282 else
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1283 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1284 int s=_value.getIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1285 int e=_value.putIndex();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1286 while (s<e)
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 byte b=_value.peek(s++);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1289 switch(b)
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1290 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1291 case '\r':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1292 case '\n':
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1293 continue;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1294 default:
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1295 buffer.put(b);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1296 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1297 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1298 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1299
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1300 BufferUtil.putCRLF(buffer);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1301 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1302
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1303 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1304 public String getName()
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 return BufferUtil.to8859_1_String(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1307 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1308
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1309 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1310 Buffer getNameBuffer()
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 return _name;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1313 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1314
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1315 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1316 public int getNameOrdinal()
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 return HttpHeaders.CACHE.getOrdinal(_name);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1319 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1320
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1321 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1322 public String getValue()
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 return BufferUtil.to8859_1_String(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1325 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1326
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1327 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1328 public Buffer getValueBuffer()
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 return _value;
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1331 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1332
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1333 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1334 public int getValueOrdinal()
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 return HttpHeaderValues.CACHE.getOrdinal(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1337 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1338
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1339 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1340 public int getIntValue()
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 return (int) getLongValue();
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1343 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1344
831
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 public long getLongValue()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1347 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1348 return BufferUtil.toLong(_value);
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1349 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1350
831
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1351 /* ------------------------------------------------------------ */
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1352 public String toString()
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1353 {
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1354 return ("[" + getName() + "=" + _value + (_next == null ? "" : "->") + "]");
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1355 }
86338c0029a9 simplify HttpFields
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1356 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1357 }