bcca941999-12-19Marcus Comstedt /*
0917d32013-03-04Anders Johansson  * $Id$
bcca941999-12-19Marcus Comstedt  * */
4a2bd12000-02-21Marcus Comstedt package com.roxen.roxen;
bcca941999-12-19Marcus Comstedt 
d8ba922000-01-10Marcus Comstedt import java.util.Map; import java.util.HashMap;
37e7962000-02-06Marcus Comstedt /** * The base class for response objects. * Use the methods in the {@link HTTP} class to create * response objects. * * @see RoxenLib * * @version $Version$ * @author marcus */
bcca941999-12-19Marcus Comstedt public abstract class RoxenResponse { int errno; String type;
89ecb71999-12-21Marcus Comstedt  long len;
68fb392000-01-10Marcus Comstedt  Map extraHeads;
d8ba922000-01-10Marcus Comstedt 
37e7962000-02-06Marcus Comstedt  /** * Add a specific HTTP header to the response * * @param name the name of the header * @param value the value of the header */
d8ba922000-01-10Marcus Comstedt  public void addHTTPHeader(String name, String value) { if(name == null) return;
68fb392000-01-10Marcus Comstedt  if(extraHeads == null) extraHeads = new HashMap(); Object o = extraHeads.get(name);
d8ba922000-01-10Marcus Comstedt  if(o != null) if(o instanceof Object[]) { String[] n = new String[((Object[])o).length+1]; System.arraycopy(o, 0, n, 0, n.length-1); n[n.length-1] = value;
68fb392000-01-10Marcus Comstedt  extraHeads.put(name, n);
d8ba922000-01-10Marcus Comstedt  } else { String[] n = new String[2]; n[0] = (String)o; n[1] = value;
68fb392000-01-10Marcus Comstedt  extraHeads.put(name, n);
d8ba922000-01-10Marcus Comstedt  } else
68fb392000-01-10Marcus Comstedt  extraHeads.put(name, value);
d8ba922000-01-10Marcus Comstedt  }
bcca941999-12-19Marcus Comstedt 
89ecb71999-12-21Marcus Comstedt  RoxenResponse(int _errno, String _type, long _len)
bcca941999-12-19Marcus Comstedt  { errno = _errno; type = _type; len = _len; } }