KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > utils > HttpHeaderUtils


1 //
2
//Informa -- RSS Library for Java
3
//Copyright (c) 2002 by Niko Schmuck
4
//
5
//Niko Schmuck
6
//http://sourceforge.net/projects/informa
7
//mailto:niko_schmuck@users.sourceforge.net
8
//
9
//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 JavaDoc;
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 JavaDoc conn, long value) {
43     if ( value > 0 )
44       conn.setIfModifiedSince( value );
45   }
46   
47   /**
48    * do nothing if etag == null otherwise add a If-None-Match property
49    * in http header
50    * @param conn
51    * @param etag
52    */

53   static public void setETagValue(HttpURLConnection JavaDoc conn, String JavaDoc etag) {
54     if (etag !=null) {
55       conn.setRequestProperty("If-None-Match", etag);
56     }
57   }
58   
59   static public long getLastModified(HttpURLConnection JavaDoc conn) {
60     long result = conn.getHeaderFieldDate("Last-Modified", 0L);
61     return result;
62   }
63   
64   static public String JavaDoc getETagValue(HttpURLConnection JavaDoc conn) {
65     return conn.getHeaderField("ETag");
66   }
67   
68   static public void setUserAgent(HttpURLConnection JavaDoc conn, String JavaDoc agent) {
69     if ( agent == null )
70       return;
71     conn.setRequestProperty("User-Agent",agent);
72   }
73 }
74
Popular Tags