Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

implement RequestHeader.setCharacterEncoding for legacy header, make sure .getProtocol returns a http version move the patch for Set-Cookie to ResponseHeader (applies only here)

reger0d3bef659bbd
diff --git a/source/net/yacy/cora/protocol/HeaderFramework.java b/source/net/yacy/cora/protocol/HeaderFramework.java
index 4cd5ed168..26fcfd540 100644
--- a/source/net/yacy/cora/protocol/HeaderFramework.java
+++ b/source/net/yacy/cora/protocol/HeaderFramework.java
@@ -33,7 +33,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
-import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import net.yacy.cora.document.encoding.ASCII;
@@ -579,138 +578,4 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stri
}
}
}
-
-
- /*
- * Patch BEGIN:
- * Name: Header Property Patch
- * Date: Fri. 13.01.2006
- * Description: Makes possible to send header properties such as cookies back to the client.
- * Part 1 of 5
- * Questions: [email protected]
- */
- /**
- * Holds header properties
- */
- //Since properties such as cookies can be multiple, we cannot use HashMap here. We have to use Vector.
- private Vector<Entry> headerProps = new Vector<Entry>();
-
- /**
- * Implementation of Map.Entry. Structure that hold two values - exactly what we need!
- */
- public static class Entry implements Map.Entry<String, String> {
- private final String k;
- private String v;
- Entry(final String k, final String v) {
- this.k = k;
- this.v = v;
- }
- @Override
- public String getKey() {
- return this.k;
- }
- @Override
- public String getValue() {
- return this.v;
- }
- @Override
- public String setValue(final String v) {
- final String r = this.v;
- this.v = v;
- return r;
- }
- }
-
- /**
- * Sets Cookie on the client machine.
- *
- * @param name Cookie name
- * @param value Cookie value
- * @param expires when should this cookie be autmatically deleted. If <b>null</b> - cookie will stay forever
- * @param path Path the cookie belongs to. Default - "/". Can be <b>null</b>.
- * @param domain Domain this cookie belongs to. Default - domain name. Can be <b>null</b>.
- * @param secure If true cookie will be send only over safe connection such as https
- * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
- */
- public void setCookie(final String name, final String value, final String expires, final String path, final String domain, final boolean secure)
- {
- /*
- * TODO:Here every value can be validated for correctness if needed
- * For example semicolon should be not in any of the values
- * However an exception in this case would be an overhead IMHO.
- */
- String cookieString = name + "=" + value + ";";
- if (expires != null) cookieString += " expires=" + expires + ";";
- if (path != null) cookieString += " path=" + path + ";";
- if (domain != null) cookieString += " domain=" + domain + ";";
- if (secure) cookieString += " secure;";
- this.headerProps.add(new Entry("Set-Cookie", cookieString));
- }
- /**
- * Sets Cookie on the client machine.
- *
- * @param name Cookie name
- * @param value Cookie value
- * @param expires when should this cookie be automatically deleted. If <b>null</b> - cookie will stay forever
- * @param path Path the cookie belongs to. Default - "/". Can be <b>null</b>.
- * @param domain Domain this cookie belongs to. Default - domain name. Can be <b>null</b>.
- *
- * Note: this cookie will be sent over each connection independent if it is safe connection or not.
- * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
- */
- public void setCookie(final String name, final String value, final String expires, final String path, final String domain)
- {
- setCookie( name, value, expires, path, domain, false);
- }
- /**
- * Sets Cookie on the client machine.
- *
- * @param name Cookie name
- * @param value Cookie value
- * @param expires when should this cookie be automatically deleted. If <b>null</b> - cookie will stay forever
- * @param path Path the cookie belongs to. Default - "/". Can be <b>null</b>.
- *
- * Note: this cookie will be sent over each connection independent if it is safe connection or not.
- * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
- */
- public void setCookie(final String name, final String value, final String expires, final String path)
- {
- setCookie( name, value, expires, path, null, false);
- }
- /**
- * Sets Cookie on the client machine.
- *
- * @param name Cookie name
- * @param value Cookie value
- * @param expires when should this cookie be automatically deleted. If <b>null</b> - cookie will stay forever
- *
- * Note: this cookie will be sent over each connection independent if it is safe connection or not.
- * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
- */
- public void setCookie(final String name, final String value, final String expires)
- {
- setCookie( name, value, expires, null, null, false);
- }
- /**
- * Sets Cookie on the client machine.
- *
- * @param name Cookie name
- * @param value Cookie value
- *
- * Note: this cookie will be sent over each connection independent if it is safe connection or not. This cookie never expires
- * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
- */
- public void setCookie(final String name, final String value )
- {
- setCookie( name, value, null, null, null, false);
- }
-
- public Vector<Entry> getAdditionalHeaderProperties() {
- return this.headerProps;
- }
-
- /*
- * Patch END:
- * Name: Header Property Patch
- */
}
diff --git a/source/net/yacy/cora/protocol/RequestHeader.java b/source/net/yacy/cora/protocol/RequestHeader.java
index ab65ac611..3fc650e5d 100644
--- a/source/net/yacy/cora/protocol/RequestHeader.java
+++ b/source/net/yacy/cora/protocol/RequestHeader.java
@@ -537,8 +537,14 @@ public class RequestHeader extends HeaderFramework implements HttpServletRequest
public void setCharacterEncoding(String env) throws UnsupportedEncodingException {
if (_request != null) {
_request.setCharacterEncoding(env);
+ } else {
+ // charset part of Content-Type header
+ // Example: "Content-Type: text/html; charset=ISO-8859-4"
+ // see https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
+ //
+ final String mime = mime();
+ super.put(CONTENT_TYPE, mime + "; charset=" + env);
}
- throw new UnsupportedOperationException("Not supported yet.");
}
@Override
@@ -618,7 +624,7 @@ public class RequestHeader extends HeaderFramework implements HttpServletRequest
if (_request != null) {
return _request.getProtocol();
} else {
- return this.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
+ return super.get(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_1_1);
}
}
diff --git a/source/net/yacy/cora/protocol/ResponseHeader.java b/source/net/yacy/cora/protocol/ResponseHeader.java
index 05e651811..741ca048c 100644
--- a/source/net/yacy/cora/protocol/ResponseHeader.java
+++ b/source/net/yacy/cora/protocol/ResponseHeader.java
@@ -23,6 +23,7 @@ package net.yacy.cora.protocol;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.util.Vector;
import org.apache.http.Header;
@@ -126,4 +127,136 @@ public class ResponseHeader extends HeaderFramework {
return x_robots_tag.toLowerCase();
}
+ /*
+ * Patch BEGIN: (moved from HeaderFramework here (2016-11-20)
+ * Name: Header Property Patch
+ * Date: Fri. 13.01.2006
+ * Description: Makes possible to send header properties such as cookies back to the client.
+ * Part 1 of 5
+ * Questions: [email protected]
+ */
+ /**
+ * Holds header properties
+ */
+ //Since properties such as cookies can be multiple, we cannot use HashMap here. We have to use Vector.
+ private Vector<Entry> headerProps = new Vector<Entry>();
+
+ /**
+ * Implementation of Map.Entry. Structure that hold two values - exactly what we need!
+ */
+ public static class Entry implements Map.Entry<String, String> {
+ private final String k;
+ private String v;
+ Entry(final String k, final String v) {
+ this.k = k;
+ this.v = v;
+ }
+ @Override
+ public String getKey() {
+ return this.k;
+ }
+ @Override
+ public String getValue() {
+ return this.v;
+ }
+ @Override
+ public String setValue(final String v) {
+ final String r = this.v;
+ this.v = v;
+ return r;
+ }
+ }
+
+ /**
+ * Sets Cookie on the client machine.
+ *
+ * @param name Cookie name
+ * @param value Cookie value
+ * @param expires when should this cookie be autmatically deleted. If <b>null</b> - cookie will stay forever
+ * @param path Path the cookie belongs to. Default - "/". Can be <b>null</b>.
+ * @param domain Domain this cookie belongs to. Default - domain name. Can be <b>null</b>.
+ * @param secure If true cookie will be send only over safe connection such as https
+ * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
+ */
+ public void setCookie(final String name, final String value, final String expires, final String path, final String domain, final boolean secure)
+ {
+ /*
+ * TODO:Here every value can be validated for correctness if needed
+ * For example semicolon should be not in any of the values
+ * However an exception in this case would be an overhead IMHO.
+ */
+ String cookieString = name + "=" + value + ";";
+ if (expires != null) cookieString += " expires=" + expires + ";";
+ if (path != null) cookieString += " path=" + path + ";";
+ if (domain != null) cookieString += " domain=" + domain + ";";
+ if (secure) cookieString += " secure;";
+ this.headerProps.add(new Entry("Set-Cookie", cookieString));
+ }
+ /**
+ * Sets Cookie on the client machine.
+ *
+ * @param name Cookie name
+ * @param value Cookie value
+ * @param expires when should this cookie be automatically deleted. If <b>null</b> - cookie will stay forever
+ * @param path Path the cookie belongs to. Default - "/". Can be <b>null</b>.
+ * @param domain Domain this cookie belongs to. Default - domain name. Can be <b>null</b>.
+ *
+ * Note: this cookie will be sent over each connection independent if it is safe connection or not.
+ * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
+ */
+ public void setCookie(final String name, final String value, final String expires, final String path, final String domain)
+ {
+ setCookie( name, value, expires, path, domain, false);
+ }
+ /**
+ * Sets Cookie on the client machine.
+ *
+ * @param name Cookie name
+ * @param value Cookie value
+ * @param expires when should this cookie be automatically deleted. If <b>null</b> - cookie will stay forever
+ * @param path Path the cookie belongs to. Default - "/". Can be <b>null</b>.
+ *
+ * Note: this cookie will be sent over each connection independent if it is safe connection or not.
+ * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
+ */
+ public void setCookie(final String name, final String value, final String expires, final String path)
+ {
+ setCookie( name, value, expires, path, null, false);
+ }
+ /**
+ * Sets Cookie on the client machine.
+ *
+ * @param name Cookie name
+ * @param value Cookie value
+ * @param expires when should this cookie be automatically deleted. If <b>null</b> - cookie will stay forever
+ *
+ * Note: this cookie will be sent over each connection independent if it is safe connection or not.
+ * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
+ */
+ public void setCookie(final String name, final String value, final String expires)
+ {
+ setCookie( name, value, expires, null, null, false);
+ }
+ /**
+ * Sets Cookie on the client machine.
+ *
+ * @param name Cookie name
+ * @param value Cookie value
+ *
+ * Note: this cookie will be sent over each connection independent if it is safe connection or not. This cookie never expires
+ * @see further documentation: <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
+ */
+ public void setCookie(final String name, final String value )
+ {
+ setCookie( name, value, null, null, null, false);
+ }
+
+ public Vector<Entry> getAdditionalHeaderProperties() {
+ return this.headerProps;
+ }
+
+ /*
+ * Patch END:
+ * Name: Header Property Patch
+ */
}