Improved javadocs and logging.

This commit is contained in:
Simone Bordet 2015-11-04 10:43:14 +01:00
parent c63ef3e08b
commit 2a765afdc6
7 changed files with 83 additions and 9 deletions

View File

@ -181,7 +181,7 @@ public class HttpConnectionOverFCGI extends AbstractConnection implements Connec
if (channels.isEmpty())
close();
else
failAndClose(new EOFException());
failAndClose(new EOFException(String.valueOf(getEndPoint())));
}
@Override

View File

@ -22,6 +22,16 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.fcgi.FCGI;
/**
* <p>Parser for the BEGIN_REQUEST frame body.</p>
* <pre>
* struct begin_request_body {
* ushort role;
* ubyte flags;
* ubyte[5] reserved;
* }
* </pre>
*/
public class BeginRequestContentParser extends ContentParser
{
private final ServerParser.Listener listener;

View File

@ -21,9 +21,28 @@ package org.eclipse.jetty.fcgi.parser;
import java.nio.ByteBuffer;
import org.eclipse.jetty.fcgi.FCGI;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* <p>Parser for FastCGI frame headers.</p>
* <pre>
* struct frame_header {
* ubyte version;
* ubyte type;
* ushort requestId;
* ushort contentLength;
* ubyte paddingLength;
* ubyte reserved;
* }
* </pre>
*
* @see Parser
*/
public class HeaderParser
{
private static final Logger LOG = Log.getLogger(Parser.class);
private State state = State.VERSION;
private int cursor;
private int version;
@ -109,6 +128,8 @@ public class HeaderParser
case RESERVED:
{
buffer.get();
if (LOG.isDebugEnabled())
LOG.debug("Parsed request {} header {} length={}", getRequest(), getFrameType(), getContentLength());
return true;
}
default:

View File

@ -20,11 +20,44 @@ package org.eclipse.jetty.fcgi.parser;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* <p>Parser for the PARAMS frame body.</p>
* <pre>
* struct small_name_small_value_params_body {
* ubyte nameLength;
* ubyte valueLength;
* ubyte[] nameBytes;
* ubyte[] valueBytes;
* }
*
* struct small_name_large_value_params_body {
* ubyte nameLength;
* uint valueLength;
* ubyte[] nameBytes;
* ubyte[] valueBytes;
* }
*
* struct large_name_small_value_params_body {
* uint nameLength;
* ubyte valueLength;
* ubyte[] nameBytes;
* ubyte[] valueBytes;
* }
*
* struct large_name_large_value_params_body {
* uint nameLength;
* uint valueLength;
* ubyte[] nameBytes;
* ubyte[] valueBytes;
* }
* </pre>
*/
public class ParamsContentParser extends ContentParser
{
private static final Logger LOG = Log.getLogger(ParamsContentParser.class);
@ -179,7 +212,7 @@ public class ParamsContentParser extends ContentParser
}
case PARAM:
{
Charset utf8 = Charset.forName("UTF-8");
Charset utf8 = StandardCharsets.UTF_8;
onParam(new String(nameBytes, utf8), new String(valueBytes, utf8));
partialReset();
if (length == 0)

View File

@ -22,6 +22,8 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.fcgi.FCGI;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* <p>The FastCGI protocol exchanges <em>frames</em>.</p>
@ -39,9 +41,14 @@ import org.eclipse.jetty.http.HttpField;
* </pre>
* <p>Depending on the {@code type}, the content may have a different format,
* so there are specialized content parsers.</p>
*
* @see HeaderParser
* @see ContentParser
*/
public abstract class Parser
{
private static final Logger LOG = Log.getLogger(Parser.class);
protected final HeaderParser headerParser = new HeaderParser();
private State state = State.HEADER;
private int padding;
@ -73,6 +80,9 @@ public abstract class Parser
else
{
ContentParser.Result result = contentParser.parse(buffer);
if (LOG.isDebugEnabled())
LOG.debug("Parsed request {} content {} result={}", headerParser.getRequest(), headerParser.getFrameType(), result);
if (result == ContentParser.Result.PENDING)
{
// Not enough data, signal to read/parse more.

View File

@ -35,8 +35,8 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* <p>The parser for STDOUT type frames.</p>
* <p>STDOUT frames contain both the HTTP headers (but not the response line)
* <p>The parser for STDOUT type frame bodies.</p>
* <p>STDOUT frame bodies contain both the HTTP headers (but not the response line)
* and the HTTP content (either Content-Length delimited or chunked).</p>
* <p>For this reason, a special HTTP parser is used to parse the frames body.
* This special HTTP parser is configured to skip the response line, and to
@ -99,12 +99,12 @@ public class ResponseContentParser extends StreamContentParser
public boolean parse(ByteBuffer buffer)
{
if (LOG.isDebugEnabled())
LOG.debug("Response {} {} content {} {}", request, FCGI.StreamType.STD_OUT, state, buffer);
int remaining = buffer.remaining();
while (remaining > 0)
{
if (LOG.isDebugEnabled())
LOG.debug("Response {} {}, state {} {}", request, FCGI.StreamType.STD_OUT, state, buffer);
switch (state)
{
case HEADERS:

View File

@ -25,8 +25,8 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* <p>A stream content parser parses frames of type STDIN, STDOUT and STDERR.</p>
* <p>STDOUT frames are handled specially by {@link ResponseContentParser}.
* <p>A stream content parser parses frame bodies of type STDIN, STDOUT and STDERR.</p>
* <p>STDOUT frame bodies are handled specially by {@link ResponseContentParser}.
*/
public class StreamContentParser extends ContentParser
{