1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.client.http;
20
21 import java.util.Enumeration;
22
23 import org.eclipse.jetty.client.HttpChannel;
24 import org.eclipse.jetty.client.HttpExchange;
25 import org.eclipse.jetty.client.api.Result;
26 import org.eclipse.jetty.http.HttpFields;
27 import org.eclipse.jetty.http.HttpHeader;
28 import org.eclipse.jetty.http.HttpHeaderValue;
29
30 public class HttpChannelOverHTTP extends HttpChannel
31 {
32 private final HttpConnectionOverHTTP connection;
33 private final HttpSenderOverHTTP sender;
34 private final HttpReceiverOverHTTP receiver;
35
36 public HttpChannelOverHTTP(HttpConnectionOverHTTP connection)
37 {
38 super(connection.getHttpDestination());
39 this.connection = connection;
40 this.sender = new HttpSenderOverHTTP(this);
41 this.receiver = new HttpReceiverOverHTTP(this);
42 }
43
44 public HttpConnectionOverHTTP getHttpConnection()
45 {
46 return connection;
47 }
48
49 @Override
50 public void send()
51 {
52 HttpExchange exchange = getHttpExchange();
53 if (exchange != null)
54 sender.send(exchange);
55 }
56
57 @Override
58 public void proceed(HttpExchange exchange, boolean proceed)
59 {
60 sender.proceed(exchange, proceed);
61 }
62
63 @Override
64 public boolean abort(Throwable cause)
65 {
66
67
68
69 sender.abort(cause);
70 return receiver.abort(cause);
71 }
72
73 public void receive()
74 {
75 receiver.receive();
76 }
77
78 @Override
79 public void exchangeTerminated(Result result)
80 {
81 super.exchangeTerminated(result);
82
83 if (result.isSucceeded())
84 {
85 HttpFields responseHeaders = result.getResponse().getHeaders();
86 Enumeration<String> values = responseHeaders.getValues(HttpHeader.CONNECTION.asString(), ",");
87 if (values != null)
88 {
89 while (values.hasMoreElements())
90 {
91 if (HttpHeaderValue.CLOSE.asString().equalsIgnoreCase(values.nextElement()))
92 {
93 connection.close();
94 return;
95 }
96 }
97 }
98 connection.release();
99 }
100 else
101 {
102 connection.close();
103 }
104 }
105
106 @Override
107 public String toString()
108 {
109 return String.format("%s@%x", getClass().getSimpleName(), hashCode());
110 }
111 }