01: //
02: //Informa -- RSS Library for Java
03: //Copyright (c) 2002 by Niko Schmuck
04: //
05: //Niko Schmuck
06: //http://sourceforge.net/projects/informa
07: //mailto:niko_schmuck@users.sourceforge.net
08: //
09: //This library is free software.
10: //
11: //You may redistribute it and/or modify it under the terms of the GNU
12: //Lesser General Public License as published by the Free Software Foundation.
13: //
14: //Version 2.1 of the license should be included with this distribution in
15: //the file LICENSE. If the license is not included with this distribution,
16: //you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17: //or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18: //MA 02139 USA.
19: //
20: //This library is distributed in the hope that it will be useful,
21: //but WITHOUT ANY WARRANTY; without even the implied waranty of
22: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23: //Lesser General Public License for more details.
24: //
25: // $Id: HttpHeaderUtils.java,v 1.3 2004/06/24 14:00:48 jga Exp $
26:
27: package de.nava.informa.utils;
28:
29: import java.net.HttpURLConnection;
30:
31: /**
32: * utilities to deal with http headers
33: * @author Jean-Guy Avelin
34: */
35: public class HttpHeaderUtils {
36:
37: /**
38: * add a if-modified-since property on http header.
39: * @param conn
40: * @param value
41: */
42: static public void setIfModifiedSince(HttpURLConnection conn,
43: long value) {
44: if (value > 0)
45: conn.setIfModifiedSince(value);
46: }
47:
48: /**
49: * do nothing if etag == null otherwise add a If-None-Match property
50: * in http header
51: * @param conn
52: * @param etag
53: */
54: static public void setETagValue(HttpURLConnection conn, String etag) {
55: if (etag != null) {
56: conn.setRequestProperty("If-None-Match", etag);
57: }
58: }
59:
60: static public long getLastModified(HttpURLConnection conn) {
61: long result = conn.getHeaderFieldDate("Last-Modified", 0L);
62: return result;
63: }
64:
65: static public String getETagValue(HttpURLConnection conn) {
66: return conn.getHeaderField("ETag");
67: }
68:
69: static public void setUserAgent(HttpURLConnection conn, String agent) {
70: if (agent == null)
71: return;
72: conn.setRequestProperty("User-Agent", agent);
73: }
74: }
|