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