/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.coyote.http2;
// Write the headers
writeFrame(headersFrameHeader, headersPayload); // Body for (int i = 0; i < bodyCount; i++) {
writeFrame(dataFrameHeader, dataPayload);
}
// The Server will process the request on a separate thread to the // incoming frames. // The request processing thread will: // - read up to 128 bytes of request body // (and issue a window update for bytes read) // - write a 403 response with no response body // The connection processing thread will: // - read the request body until the flow control window is exhausted // - reset the stream if further DATA frames are received
parser.readFrame();
// Check for reset and exit if found if (checkReset()) { return;
}
// Not window update, not reset, must be the headers Assert.assertEquals("3-HeadersStart\n" + "3-Header-[:status]-[403]\n" + "3-Header-[content-length]-[0]\n" + "3-Header-[date]-[Wed, 11 Nov 2015 19:18:42 GMT]\n" + "3-HeadersEnd\n", output.getTrace());
output.clearTrace();
parser.readFrame();
// Check for reset and exit if found if (checkReset()) { return;
}
// Not window update, not reset, must be the response body Assert.assertEquals("3-Body-0\n" + "3-EndOfStream\n", output.getTrace());
output.clearTrace();
parser.readFrame();
Assert.assertTrue(checkReset());
// If there are any more frames after this, ignore them
}
/* * Looking for a RST frame with error type 3 (flow control error). * * If there is a flow control window update for stream 0 it may be followed by one for stream 3. * * If there is a flow control window update for stream 3 it will always be preceded by one for stream 0.
*/ privateboolean checkReset() throws IOException, Http2Exception { int lastConnectionFlowControlWindowUpdate = -1; while (true) {
String trace = output.getTrace(); if (trace.startsWith("3-RST-[3]\n")) { // This is the reset we are looking for returntrue;
} elseif (trace.startsWith("3-RST-[")) { // Probably error type 8 (cancel) - ignore
} elseif (trace.startsWith("0-WindowSize-[")) { // Connection flow control window update
lastConnectionFlowControlWindowUpdate = Integer.parseInt(trace.substring(14, trace.length() - 2));
} elseif (trace.startsWith("3-WindowSize-[")) { // Stream flow control window update // Must be same size as last connection flow control window // update. True for Tomcat anyway. Assert.assertEquals("3-WindowSize-[" + lastConnectionFlowControlWindowUpdate + "]\n", trace);
} else { returnfalse;
}
output.clearTrace();
parser.readFrame();
}
}
@Override protectedvoid doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Read up to 128 bytes and then return a 403 response
InputStream is = req.getInputStream(); byte[] buf = newbyte[128]; int toRead = 128;
int read = is.read(buf); while (read != -1 && toRead > 0) {
toRead -= read;
read = is.read(buf);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.