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