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

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

Issue 2805053005: [Cronet] Enable Brotli (Closed)
Patch Set: add test 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 ByteBuf content = ctx.alloc().buffer();
185 byte[] quickfoxCompressed = {0x0b, 0x15, -1, 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69,
186 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20,
187 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74, 0x68,
188 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67, 0x03};
mef 2017/04/14 13:42:04 I'm curious why 0x03 ->0x00?
189 content.setBytes(0, quickfoxCompressed);
190 responseHeaders.add("content-encoding", "br");
191 encoder().writeHeaders(ctx, streamId, responseHeaders, 0, false, ctx .newPromise());
192 encoder().writeData(ctx, streamId, content, 0, true, ctx.newPromise( ));
193 ctx.flush();
194 }
195 }
196
177 private static Http2Headers createDefaultResponseHeaders() { 197 private static Http2Headers createDefaultResponseHeaders() {
178 return new DefaultHttp2Headers().status(OK.codeAsText()); 198 return new DefaultHttp2Headers().status(OK.codeAsText());
179 } 199 }
180 200
181 private static Http2Headers createResponseHeadersFromRequestHeaders( 201 private static Http2Headers createResponseHeadersFromRequestHeaders(
182 Http2Headers requestHeaders) { 202 Http2Headers requestHeaders) {
183 // Create response headers by echoing request headers. 203 // Create response headers by echoing request headers.
184 Http2Headers responseHeaders = new DefaultHttp2Headers().status(OK.codeA sText()); 204 Http2Headers responseHeaders = new DefaultHttp2Headers().status(OK.codeA sText());
185 for (Map.Entry<CharSequence, CharSequence> header : requestHeaders) { 205 for (Map.Entry<CharSequence, CharSequence> header : requestHeaders) {
186 if (!header.getKey().toString().startsWith(":")) { 206 if (!header.getKey().toString().startsWith(":")) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (path.startsWith(ECHO_STREAM_PATH)) { 243 if (path.startsWith(ECHO_STREAM_PATH)) {
224 responder = new EchoStreamResponder(); 244 responder = new EchoStreamResponder();
225 } else if (path.startsWith(ECHO_TRAILERS_PATH)) { 245 } else if (path.startsWith(ECHO_TRAILERS_PATH)) {
226 responder = new EchoTrailersResponder(); 246 responder = new EchoTrailersResponder();
227 } else if (path.startsWith(ECHO_ALL_HEADERS_PATH)) { 247 } else if (path.startsWith(ECHO_ALL_HEADERS_PATH)) {
228 responder = new EchoAllHeadersResponder(); 248 responder = new EchoAllHeadersResponder();
229 } else if (path.startsWith(ECHO_HEADER_PATH)) { 249 } else if (path.startsWith(ECHO_HEADER_PATH)) {
230 responder = new EchoHeaderResponder(); 250 responder = new EchoHeaderResponder();
231 } else if (path.startsWith(ECHO_METHOD_PATH)) { 251 } else if (path.startsWith(ECHO_METHOD_PATH)) {
232 responder = new EchoMethodResponder(); 252 responder = new EchoMethodResponder();
253 } else if (path.startsWith(SERVE_SIMPLE_BROTLI_RESPONSE)) {
254 responder = new ServeSimpleBrotliResponder();
233 } else { 255 } else {
234 responder = new RequestResponder(); 256 responder = new RequestResponder();
235 } 257 }
236 258
237 responder.onHeadersRead(ctx, streamId, endOfStream, headers); 259 responder.onHeadersRead(ctx, streamId, endOfStream, headers);
238 260
239 if (!endOfStream) { 261 if (!endOfStream) {
240 mResponderMap.put(streamId, responder); 262 mResponderMap.put(streamId, responder);
241 } 263 }
242 } 264 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 ByteBuf debugData) throws Http2Exception {} 300 ByteBuf debugData) throws Http2Exception {}
279 301
280 @Override 302 @Override
281 public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) 303 public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement)
282 throws Http2Exception {} 304 throws Http2Exception {}
283 305
284 @Override 306 @Override
285 public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int st reamId, 307 public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int st reamId,
286 Http2Flags flags, ByteBuf payload) throws Http2Exception {} 308 Http2Flags flags, ByteBuf payload) throws Http2Exception {}
287 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698