Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2012-06-05 12:02:44 +0000
committerGreg Wilkins2012-06-05 12:02:44 +0000
commitc318cb8167583a2a2adeebcd2eb9cca3bfabaaa6 (patch)
tree0006d78642d03e3ac7ed8061b1db3c1354505ff8 /jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
parent96cbd53c472f5f79d5866b004c84b1e2e25d348d (diff)
downloadorg.eclipse.jetty.project-c318cb8167583a2a2adeebcd2eb9cca3bfabaaa6.tar.gz
org.eclipse.jetty.project-c318cb8167583a2a2adeebcd2eb9cca3bfabaaa6.tar.xz
org.eclipse.jetty.project-c318cb8167583a2a2adeebcd2eb9cca3bfabaaa6.zip
jetty-9 jetty-security passing tests
Diffstat (limited to 'jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java')
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java39
1 files changed, 28 insertions, 11 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
index 6322739f74..f1081bb81e 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
@@ -574,8 +574,9 @@ public class HttpFields implements Iterable<HttpFields.Field>
*/
public void add(String name, String value) throws IllegalArgumentException
{
- if (value == null) throw new IllegalArgumentException("null value");
-
+ if (value == null)
+ return;
+
Field field = _names.get(name);
Field last = null;
while (field != null)
@@ -890,15 +891,15 @@ public class HttpFields implements Iterable<HttpFields.Field>
}
/* -------------------------------------------------------------- */
- public void putTo(ByteBuffer buffer) throws IOException
+ public void putTo(ByteBuffer bufferInFillMode) throws IOException
{
for (int i = 0; i < _fields.size(); i++)
{
Field field = _fields.get(i);
if (field != null)
- field.putTo(buffer);
+ field.putTo(bufferInFillMode);
}
- BufferUtil.putCRLF(buffer);
+ BufferUtil.putCRLF(bufferInFillMode);
}
/* -------------------------------------------------------------- */
@@ -1146,7 +1147,7 @@ public class HttpFields implements Iterable<HttpFields.Field>
}
/* ------------------------------------------------------------ */
- private byte[] toSanitisedBytes(String s)
+ private byte[] toSanitisedName(String s)
{
byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
for (int i=bytes.length;i-->0;)
@@ -1161,6 +1162,22 @@ public class HttpFields implements Iterable<HttpFields.Field>
}
return bytes;
}
+
+ /* ------------------------------------------------------------ */
+ private byte[] toSanitisedValue(String s)
+ {
+ byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
+ for (int i=bytes.length;i-->0;)
+ {
+ switch(bytes[i])
+ {
+ case '\r':
+ case '\n':
+ bytes[i]=(byte)'?';
+ }
+ }
+ return bytes;
+ }
/* ------------------------------------------------------------ */
public void putTo(ByteBuffer bufferInFillMode)
@@ -1176,16 +1193,16 @@ public class HttpFields implements Iterable<HttpFields.Field>
if (value!=null)
bufferInFillMode.put(value.toBuffer());
else
- bufferInFillMode.put(toSanitisedBytes(_value));
+ bufferInFillMode.put(toSanitisedValue(_value));
}
else
- bufferInFillMode.put(toSanitisedBytes(_value));
+ bufferInFillMode.put(toSanitisedValue(_value));
}
else
{
- bufferInFillMode.put(toSanitisedBytes(_name));
+ bufferInFillMode.put(toSanitisedName(_name));
bufferInFillMode.put(__colon_space);
- bufferInFillMode.put(toSanitisedBytes(_value));
+ bufferInFillMode.put(toSanitisedValue(_value));
}
BufferUtil.putCRLF(bufferInFillMode);
@@ -1194,7 +1211,7 @@ public class HttpFields implements Iterable<HttpFields.Field>
/* ------------------------------------------------------------ */
public void putValueTo(ByteBuffer buffer)
{
- buffer.put(toSanitisedBytes(_value));
+ buffer.put(toSanitisedValue(_value));
}
/* ------------------------------------------------------------ */

Back to the top