1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.eclipse.jetty.spdy.server.http;
21
22 import org.eclipse.jetty.io.EndPoint;
23 import org.eclipse.jetty.server.Connector;
24 import org.eclipse.jetty.server.HttpConfiguration;
25 import org.eclipse.jetty.spdy.api.DataInfo;
26 import org.eclipse.jetty.spdy.api.HeadersInfo;
27 import org.eclipse.jetty.spdy.api.PushInfo;
28 import org.eclipse.jetty.spdy.api.ReplyInfo;
29 import org.eclipse.jetty.spdy.api.Stream;
30 import org.eclipse.jetty.spdy.api.StreamFrameListener;
31 import org.eclipse.jetty.spdy.api.SynInfo;
32 import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
33 import org.eclipse.jetty.spdy.server.SPDYServerConnectionFactory;
34 import org.eclipse.jetty.util.Fields;
35 import org.eclipse.jetty.util.annotation.Name;
36 import org.eclipse.jetty.util.log.Log;
37 import org.eclipse.jetty.util.log.Logger;
38
39 public class HTTPSPDYServerConnectionFactory extends SPDYServerConnectionFactory implements HttpConfiguration.ConnectionFactory
40 {
41 private static final String CHANNEL_ATTRIBUTE = "org.eclipse.jetty.spdy.server.http.HTTPChannelOverSPDY";
42 private static final Logger logger = Log.getLogger(HTTPSPDYServerConnectionFactory.class);
43
44 private final PushStrategy pushStrategy;
45 private final HttpConfiguration httpConfiguration;
46
47 public HTTPSPDYServerConnectionFactory(
48 @Name("version") int version,
49 @Name("config") HttpConfiguration config)
50 {
51 this(version,config,new PushStrategy.None());
52 }
53
54 public HTTPSPDYServerConnectionFactory(
55 @Name("version") int version,
56 @Name("config") HttpConfiguration config,
57 @Name("pushStrategy") PushStrategy pushStrategy)
58 {
59 super(version);
60 this.pushStrategy = pushStrategy;
61 httpConfiguration = config;
62 addBean(httpConfiguration);
63 }
64
65 @Override
66 public HttpConfiguration getHttpConfiguration()
67 {
68 return httpConfiguration;
69 }
70
71 @Override
72 protected ServerSessionFrameListener provideServerSessionFrameListener(Connector connector, EndPoint endPoint)
73 {
74 return new HTTPServerFrameListener(connector,endPoint);
75 }
76
77 private class HTTPServerFrameListener extends ServerSessionFrameListener.Adapter implements StreamFrameListener
78 {
79 private final Connector connector;
80 private final EndPoint endPoint;
81
82 public HTTPServerFrameListener(Connector connector,EndPoint endPoint)
83 {
84 this.endPoint = endPoint;
85 this.connector=connector;
86 }
87
88 @Override
89 public StreamFrameListener onSyn(final Stream stream, SynInfo synInfo)
90 {
91
92
93
94
95
96
97 logger.debug("Received {} on {}", synInfo, stream);
98
99 Fields headers = synInfo.getHeaders();
100 HttpTransportOverSPDY transport = new HttpTransportOverSPDY(connector, httpConfiguration, endPoint, pushStrategy, stream, headers);
101 HttpInputOverSPDY input = new HttpInputOverSPDY();
102 HttpChannelOverSPDY channel = new HttpChannelOverSPDY(connector, httpConfiguration, endPoint, transport, input, stream);
103 stream.setAttribute(CHANNEL_ATTRIBUTE, channel);
104
105 channel.requestStart(headers, synInfo.isClose());
106
107 if (headers.isEmpty())
108 {
109
110 return this;
111 }
112 else
113 {
114 if (synInfo.isClose())
115 return null;
116 else
117 return this;
118 }
119 }
120
121 @Override
122 public void onReply(Stream stream, ReplyInfo replyInfo)
123 {
124
125 }
126
127 @Override
128 public void onHeaders(Stream stream, HeadersInfo headersInfo)
129 {
130 logger.debug("Received {} on {}", headersInfo, stream);
131 HttpChannelOverSPDY channel = (HttpChannelOverSPDY)stream.getAttribute(CHANNEL_ATTRIBUTE);
132 channel.requestHeaders(headersInfo.getHeaders(), headersInfo.isClose());
133 }
134
135 @Override
136 public StreamFrameListener onPush(Stream stream, PushInfo pushInfo)
137 {
138 return null;
139 }
140
141 @Override
142 public void onData(Stream stream, final DataInfo dataInfo)
143 {
144 logger.debug("Received {} on {}", dataInfo, stream);
145 HttpChannelOverSPDY channel = (HttpChannelOverSPDY)stream.getAttribute(CHANNEL_ATTRIBUTE);
146 channel.requestContent(dataInfo, dataInfo.isClose());
147 }
148 }
149 }