Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: components/cronet/android/test/src/org/chromium/net/Http2TestHandler.java

Issue 2805053005: [Cronet] Enable Brotli (Closed)
Patch Set: get rid of terminator Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import org.chromium.base.Log; 7 import org.chromium.base.Log;
8 8
9 import java.util.HashMap; 9 import java.util.HashMap;
10 import java.util.Locale; 10 import java.util.Locale;
(...skipping 23 matching lines...) Expand all
34 /** 34 /**
35 * HTTP/2 test handler for Cronet BidirectionalStream tests. 35 * HTTP/2 test handler for Cronet BidirectionalStream tests.
36 */ 36 */
37 public final class Http2TestHandler extends Http2ConnectionHandler implements Ht tp2FrameListener { 37 public final class Http2TestHandler extends Http2ConnectionHandler implements Ht tp2FrameListener {
38 // Some Url Paths that have special meaning. 38 // Some Url Paths that have special meaning.
39 public static final String ECHO_ALL_HEADERS_PATH = "/echoallheaders"; 39 public static final String ECHO_ALL_HEADERS_PATH = "/echoallheaders";
40 public static final String ECHO_HEADER_PATH = "/echoheader"; 40 public static final String ECHO_HEADER_PATH = "/echoheader";
41 public static final String ECHO_METHOD_PATH = "/echomethod"; 41 public static final String ECHO_METHOD_PATH = "/echomethod";
42 public static final String ECHO_STREAM_PATH = "/echostream"; 42 public static final String ECHO_STREAM_PATH = "/echostream";
43 public static final String ECHO_TRAILERS_PATH = "/echotrailers"; 43 public static final String ECHO_TRAILERS_PATH = "/echotrailers";
44 public static final String SERVE_SIMPLE_BROTLI_RESPONSE = "/simplebrotli";
44 45
45 private static final String TAG = Http2TestHandler.class.getSimpleName(); 46 private static final String TAG = Http2TestHandler.class.getSimpleName();
46 private static final Http2FrameLogger sLogger = 47 private static final Http2FrameLogger sLogger =
47 new Http2FrameLogger(INFO, Http2TestHandler.class); 48 new Http2FrameLogger(INFO, Http2TestHandler.class);
48 private static final ByteBuf RESPONSE_BYTES = 49 private static final ByteBuf RESPONSE_BYTES =
49 unreleasableBuffer(copiedBuffer("HTTP/2 Test Server", CharsetUtil.UT F_8)); 50 unreleasableBuffer(copiedBuffer("HTTP/2 Test Server", CharsetUtil.UT F_8));
50 51
51 private HashMap<Integer, RequestResponder> mResponderMap = new HashMap<>(); 52 private HashMap<Integer, RequestResponder> mResponderMap = new HashMap<>();
52 53
53 /** 54 /**
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 ctx, streamId, createDefaultResponseHeaders(), 0, false, ctx .newPromise()); 168 ctx, streamId, createDefaultResponseHeaders(), 0, false, ctx .newPromise());
168 encoder().writeData( 169 encoder().writeData(
169 ctx, streamId, RESPONSE_BYTES.duplicate(), 0, false, ctx.new Promise()); 170 ctx, streamId, RESPONSE_BYTES.duplicate(), 0, false, ctx.new Promise());
170 Http2Headers responseTrailers = createResponseHeadersFromRequestHead ers(headers).add( 171 Http2Headers responseTrailers = createResponseHeadersFromRequestHead ers(headers).add(
171 "trailer", "value1", "Value2"); 172 "trailer", "value1", "Value2");
172 encoder().writeHeaders(ctx, streamId, responseTrailers, 0, true, ctx .newPromise()); 173 encoder().writeHeaders(ctx, streamId, responseTrailers, 0, true, ctx .newPromise());
173 ctx.flush(); 174 ctx.flush();
174 } 175 }
175 } 176 }
176 177
178 // A RequestResponder that serves a simple Brotli-encoded response.
179 private class ServeSimpleBrotliResponder extends RequestResponder {
180 @Override
181 void onHeadersRead(ChannelHandlerContext ctx, int streamId, boolean endO fStream,
182 Http2Headers headers) {
183 Http2Headers responseHeaders = new DefaultHttp2Headers().status(OK.c odeAsText());
184 byte[] quickfoxCompressed = {0x0b, 0x15, -1, 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69,
mef 2017/04/14 17:02:07 The third byte in curl https://raw.githubuserconte
xunjieli 2017/04/14 17:25:25 The third byte is 0x80, but Java byte is signed so
mef 2017/04/14 17:40:59 I see, that might be the problem as -1 is 0xFF, no
xunjieli 2017/04/14 18:24:15 Done. sorry for the very stupid error. Not sure wh
mef 2017/04/14 18:34:58 No problem, but original test data has the '0x03'
xunjieli 2017/04/14 18:47:37 Done. You are right! That fixed it. Thanks for cat
185 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20,
186 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74, 0x68,
187 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67};
188 ByteBuf content = copiedBuffer(quickfoxCompressed);
189 responseHeaders.add("content-encoding", "br");
190 encoder().writeHeaders(ctx, streamId, responseHeaders, 0, false, ctx .newPromise());
191 encoder().writeData(ctx, streamId, content, 0, true, ctx.newPromise( ));
192 ctx.flush();
193 }
194 }
195
177 private static Http2Headers createDefaultResponseHeaders() { 196 private static Http2Headers createDefaultResponseHeaders() {
178 return new DefaultHttp2Headers().status(OK.codeAsText()); 197 return new DefaultHttp2Headers().status(OK.codeAsText());
179 } 198 }
180 199
181 private static Http2Headers createResponseHeadersFromRequestHeaders( 200 private static Http2Headers createResponseHeadersFromRequestHeaders(
182 Http2Headers requestHeaders) { 201 Http2Headers requestHeaders) {
183 // Create response headers by echoing request headers. 202 // Create response headers by echoing request headers.
184 Http2Headers responseHeaders = new DefaultHttp2Headers().status(OK.codeA sText()); 203 Http2Headers responseHeaders = new DefaultHttp2Headers().status(OK.codeA sText());
185 for (Map.Entry<CharSequence, CharSequence> header : requestHeaders) { 204 for (Map.Entry<CharSequence, CharSequence> header : requestHeaders) {
186 if (!header.getKey().toString().startsWith(":")) { 205 if (!header.getKey().toString().startsWith(":")) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (path.startsWith(ECHO_STREAM_PATH)) { 242 if (path.startsWith(ECHO_STREAM_PATH)) {
224 responder = new EchoStreamResponder(); 243 responder = new EchoStreamResponder();
225 } else if (path.startsWith(ECHO_TRAILERS_PATH)) { 244 } else if (path.startsWith(ECHO_TRAILERS_PATH)) {
226 responder = new EchoTrailersResponder(); 245 responder = new EchoTrailersResponder();
227 } else if (path.startsWith(ECHO_ALL_HEADERS_PATH)) { 246 } else if (path.startsWith(ECHO_ALL_HEADERS_PATH)) {
228 responder = new EchoAllHeadersResponder(); 247 responder = new EchoAllHeadersResponder();
229 } else if (path.startsWith(ECHO_HEADER_PATH)) { 248 } else if (path.startsWith(ECHO_HEADER_PATH)) {
230 responder = new EchoHeaderResponder(); 249 responder = new EchoHeaderResponder();
231 } else if (path.startsWith(ECHO_METHOD_PATH)) { 250 } else if (path.startsWith(ECHO_METHOD_PATH)) {
232 responder = new EchoMethodResponder(); 251 responder = new EchoMethodResponder();
252 } else if (path.startsWith(SERVE_SIMPLE_BROTLI_RESPONSE)) {
253 responder = new ServeSimpleBrotliResponder();
233 } else { 254 } else {
234 responder = new RequestResponder(); 255 responder = new RequestResponder();
235 } 256 }
236 257
237 responder.onHeadersRead(ctx, streamId, endOfStream, headers); 258 responder.onHeadersRead(ctx, streamId, endOfStream, headers);
238 259
239 if (!endOfStream) { 260 if (!endOfStream) {
240 mResponderMap.put(streamId, responder); 261 mResponderMap.put(streamId, responder);
241 } 262 }
242 } 263 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 ByteBuf debugData) throws Http2Exception {} 299 ByteBuf debugData) throws Http2Exception {}
279 300
280 @Override 301 @Override
281 public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) 302 public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement)
282 throws Http2Exception {} 303 throws Http2Exception {}
283 304
284 @Override 305 @Override
285 public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int st reamId, 306 public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int st reamId,
286 Http2Flags flags, ByteBuf payload) throws Http2Exception {} 307 Http2Flags flags, ByteBuf payload) throws Http2Exception {}
287 } 308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698