diff --git a/src/zutil/net/http/HttpHeaderParser.java b/src/zutil/net/http/HttpHeaderParser.java index 0772d71..00bd7c9 100755 --- a/src/zutil/net/http/HttpHeaderParser.java +++ b/src/zutil/net/http/HttpHeaderParser.java @@ -40,7 +40,6 @@ public class HttpHeaderParser { private static final Pattern PATTERN_COLON = Pattern.compile(":"); private static final Pattern PATTERN_EQUAL = Pattern.compile("="); private static final Pattern PATTERN_AND = Pattern.compile("&"); - private static final Pattern PATTERN_SEMICOLON = Pattern.compile(";"); private InputStream in; @@ -84,7 +83,7 @@ public class HttpHeaderParser { } // Post processing - parseHeaderValue(header.getCookieMap(), header.getHeader(HEADER_COOKIE)); + parseCookieValues(header.getCookieMap(), header.getHeader(HEADER_COOKIE)); header.setInputStream(in); return header; } @@ -144,17 +143,27 @@ public class HttpHeaderParser { (data.length>1 ? data[1] : "").trim()); //Value } + /** + * Parses a raw cookie header into key and value pairs + * + * @param map the Map where the cookies will be stored. + * @param cookieValue the raw cookie header value String that will be parsed + */ + public static void parseCookieValues(Map map, String cookieValue){ + parseHeaderValues(map, cookieValue, ";"); + } /** * Parses a header value string that contains key and value paired data and * stores them in a HashMap. If a pair only contain a key the the value * will be set as a empty string. * - * @param map the Map where the cookies will be stored. - * @param cookieHeader the raw cookie header String that will be parsed + * @param map the Map where key and values will be stored. + * @param headerValue the raw header value String that will be parsed. + * @param delimiter the delimiter that separates key and value pairs (e.g. ';' for Cookies or ',' for Cache-Control) */ - public static void parseHeaderValue(Map map, String cookieHeader){ - if(cookieHeader != null && !cookieHeader.isEmpty()){ - String[] tmp = PATTERN_SEMICOLON.split(cookieHeader); + public static void parseHeaderValues(Map map, String headerValue, String delimiter){ + if(headerValue != null && !headerValue.isEmpty()){ + String[] tmp = headerValue.split(delimiter); for(String cookie : tmp){ String[] tmp2 = PATTERN_EQUAL.split(cookie, 2); map.put( diff --git a/src/zutil/net/http/HttpPrintStream.java b/src/zutil/net/http/HttpPrintStream.java index 0bf2cd7..6f4b178 100755 --- a/src/zutil/net/http/HttpPrintStream.java +++ b/src/zutil/net/http/HttpPrintStream.java @@ -244,11 +244,11 @@ public class HttpPrintStream extends OutputStream{ else{ for(String key : cookies.keySet()){ out.print("Set-Cookie: " + key + "=" + cookies.get(key) + ";"); - out.print(System.lineSeparator()); + out.println(); } } } - out.print(System.lineSeparator()); + out.println(); cookies = null; } out.print(s); @@ -307,10 +307,6 @@ public class HttpPrintStream extends OutputStream{ out.write(buf, off, len); } - private void rawWrite(String s) throws IOException { - out.write(s.getBytes()); - } - private String getStatusString(int type){ switch(type){ case 100: return "Continue"; diff --git a/src/zutil/net/http/multipart/MultipartParser.java b/src/zutil/net/http/multipart/MultipartParser.java index 5b438fa..0fa5cfd 100755 --- a/src/zutil/net/http/multipart/MultipartParser.java +++ b/src/zutil/net/http/multipart/MultipartParser.java @@ -152,7 +152,7 @@ public class MultipartParser implements Iterable{ // Parse String disposition = headers.get(HEADER_CONTENT_DISPOSITION); if (disposition != null){ - HttpHeaderParser.parseHeaderValue(headers, disposition); + HttpHeaderParser.parseCookieValues(headers, disposition); if (headers.containsKey("form-data")){ if (headers.containsKey("filename")){ MultipartFileField field = new MultipartFileField(headers, boundaryIn); diff --git a/src/zutil/net/ssdp/SSDPClient.java b/src/zutil/net/ssdp/SSDPClient.java index 7516845..b4c410f 100755 --- a/src/zutil/net/ssdp/SSDPClient.java +++ b/src/zutil/net/ssdp/SSDPClient.java @@ -258,13 +258,10 @@ public class SSDPClient extends ThreadedUDPNetwork implements ThreadedUDPNetwork private long getCacheTime(String cache_control){ long ret = 0; - String[] tmp = cache_control.split(","); - for( String element : tmp ){ - element = element.replaceAll("\\s", "").toLowerCase(); - if( element.startsWith("max-age=") ){ - ret = Long.parseLong( element.substring( "max-age=".length() ) ); - } - } + HashMap tmpMap = new HashMap<>(); + HttpHeaderParser.parseHeaderValues(tmpMap, cache_control, ","); + if(tmpMap.containsKey("max-age")) + ret = Long.parseLong( tmpMap.get("max-age") ); return ret; } diff --git a/test/zutil/net/dns/MulticastDNSClientTest.java b/test/zutil/net/dns/MulticastDNSClientTest.java index e48f935..d9ca5c5 100755 --- a/test/zutil/net/dns/MulticastDNSClientTest.java +++ b/test/zutil/net/dns/MulticastDNSClientTest.java @@ -12,6 +12,7 @@ public class MulticastDNSClientTest { public static void main(String[] args) throws IOException { MulticastDNSClient mdns = new MulticastDNSClient(); mdns.start(); - mdns.sendProbe("apple.local"); + //mdns.sendProbe("appletv.local"); + mdns.sendProbe("_services._dns-sd._udp.local"); } }