1 package org.mortbay.jetty.client;
2
3 import java.io.IOException;
4
5 import org.mortbay.io.Buffer;
6 import org.mortbay.jetty.HttpFields;
7
8
9
10
11
12
13
14 public class CachedExchange extends HttpExchange
15 {
16 int _responseStatus;
17 HttpFields _responseFields;
18
19 public CachedExchange(boolean cacheFields)
20 {
21 if (cacheFields)
22 _responseFields = new HttpFields();
23 }
24
25
26 public int getResponseStatus()
27 {
28 if (_status < HttpExchange.STATUS_PARSING_HEADERS)
29 throw new IllegalStateException("Response not received");
30 return _responseStatus;
31 }
32
33
34 public HttpFields getResponseFields()
35 {
36 if (_status < HttpExchange.STATUS_PARSING_CONTENT)
37 throw new IllegalStateException("Headers not complete");
38 return _responseFields;
39 }
40
41
42 protected void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
43 {
44 _responseStatus = status;
45 super.onResponseStatus(version,status,reason);
46 }
47
48
49 protected void onResponseHeader(Buffer name, Buffer value) throws IOException
50 {
51 if (_responseFields != null)
52 _responseFields.add(name,value);
53 super.onResponseHeader(name,value);
54 }
55
56 }