1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.httpclient;
24
25 import java.util.logging.Logger;
26
27 import org.apache.commons.httpclient.Header;
28 import org.apache.commons.httpclient.HttpConnection;
29 import org.apache.commons.httpclient.HttpMethod;
30 import org.archive.util.HttpRecorder;
31
32
33 /***
34 * This class encapsulates the specializations supplied by the
35 * overrides {@link HttpRecorderGetMethod} and {@link HttpRecorderPostMethod}.
36 *
37 * It keeps instance of HttpRecorder and HttpConnection.
38 *
39 * @author stack
40 * @version $Revision: 3351 $, $Date: 2005-04-07 21:44:47 +0000 (Thu, 07 Apr 2005) $
41 */
42 public class HttpRecorderMethod {
43 protected static Logger logger =
44 Logger.getLogger(HttpRecorderMethod.class.getName());
45
46 /***
47 * Instance of http recorder we're using recording this http get.
48 */
49 private HttpRecorder httpRecorder = null;
50
51 /***
52 * Save around so can force close.
53 *
54 * See [ 922080 ] IllegalArgumentException (size is wrong).
55 * https://sourceforge.net/tracker/?func=detail&aid=922080&group_id=73833&atid=539099
56 */
57 private HttpConnection connection = null;
58
59
60 public HttpRecorderMethod(HttpRecorder recorder) {
61 this.httpRecorder = recorder;
62 }
63
64 public void markContentBegin(HttpConnection c) {
65 if (c != this.connection) {
66
67
68
69 throw new IllegalArgumentException("Connections differ: " +
70 this.connection + " " + c + " " +
71 Thread.currentThread().getName());
72 }
73 this.httpRecorder.markContentBegin();
74 }
75
76 /***
77 * @return Returns the connection.
78 */
79 public HttpConnection getConnection() {
80 return this.connection;
81 }
82
83 /***
84 * @param connection The connection to set.
85 */
86 public void setConnection(HttpConnection connection) {
87 this.connection = connection;
88 }
89 /***
90 * @return Returns the httpRecorder.
91 */
92 public HttpRecorder getHttpRecorder() {
93 return httpRecorder;
94 }
95
96 /***
97 * If a 'Proxy-Connection' header has been added to the request,
98 * it'll be of a 'keep-alive' type. Until we support 'keep-alives',
99 * override the Proxy-Connection setting and instead pass a 'close'
100 * (Otherwise every request has to timeout before we notice
101 * end-of-document).
102 * @param method Method to find proxy-connection header in.
103 */
104 public void handleAddProxyConnectionHeader(HttpMethod method) {
105 Header h = method.getRequestHeader("Proxy-Connection");
106 if (h != null) {
107 h.setValue("close");
108 method.setRequestHeader(h);
109 }
110 }
111 }