Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.http4s.blaze.http.http_parser;
  
  
  
  
  public abstract class Http1ServerParser extends BodyAndHeaderParser {
  
     private enum LineState {
         START,
         METHOD,
         SPACE1,
         URI,
         SPACE2,
         REQUEST_VERSION,
         END,
     }
 
 
 
     private final int maxRequestLineSize;
 
 
     /* ------------------------------------------------------------------- */
 
     private LineState _lineState = .;
 
     private String _methodString;
     private String _uriString;
 
 
     /* ------------------------------------------------------------------ */

    
This is the method called by parser when the HTTP request line is parsed

Parameters:
methodString The method as a string
uri The raw bytes of the URI. These are copied into a ByteBuffer that will not be changed until this parser is reset and reused.
majorversion major version
minorversion minor version
Returns:
true if handling parsing should return.
 
     public abstract boolean submitRequestLine(String methodStringString uriString schemeint majorversionint minorversion);
 
     /* ------------------------------------------------------------------ */
 
     public final boolean requestLineComplete() {
         return  == .;
     }
 
     /* ------------------------------------------------------------------ */
 
     @Override
     public void reset() {
         super.reset();
         _internalReset();
     }
 
     private void _internalReset() {
          = .;
     }
 
     /* ------------------------------------------------------------------ */
 
     @Override
     public void shutdownParser() {
         super.shutdownParser();
          = .;
     }
 
     /* ------------------------------------------------------------------ */
     // the sole Constructor
 
     public Http1ServerParser(int maxReqLenint maxHeaderLengthint initialBufferSizeint maxChunkSize) {
         super(initialBufferSizemaxHeaderLengthmaxChunkSize);
 
         this. = maxReqLen;
         _internalReset();
     }
 
     public Http1ServerParser(int maxReqLenint maxHeaderLengthint initialBufferSize) {
         this(maxReqLenmaxHeaderLengthinitialBufferSize.);
     }
 
     public Http1ServerParser(int initialBufferSize) {
         this(2048, 40*1024, initialBufferSize);
     }
 
     public Http1ServerParser() { this(10*1024); }
 
     /* ------------------------------------------------------------------ */
 
     @Override
     public boolean mayHaveBody() {
         return  == null ||  == "POST" ||  == "PUT";
     }
 
     /* ------------------------------------------------------------------ */

    
parses the request line. Returns true if completed successfully, false if needs input
    protected final boolean parseRequestLine(ByteBuffer inthrows InvalidStateBadRequest {
        lineLoop: while(true) {
            char ch;
            switch () {
                case :
                     = .;
                    resetLimit();
                case :
                    for(ch = next(infalse); . <= ch && ch <= .ch = next(infalse)) {
                        putChar(ch);
                    }
                    if (ch == 0) return false;
                     = getString();
                    clearBuffer();
                    if (!HttpTokens.isWhiteSpace(ch)) {
                        String badmethod =  + (char)ch;
                        shutdownParser();
                        throw new BadRequest("Invalid request method: '" + badmethod + "'");
                    }
                    = .;
                case :
                    // Eat whitespace
                    for(ch = next(infalse); ch == . || ch == .ch = next(infalse));
                    if (ch == 0) return false;
                    putChar(ch);
                     = .;
                case :
                    for(ch = next(infalse); ch != . && ch != .ch = next(infalse)) {
                        if (ch == 0) return false;
                        putChar(ch);
                    }
                     = getString();
                    clearBuffer();
                     = .;
                case :
                    // Eat whitespace
                    for(ch = next(infalse); ch == . || ch == .ch = next(infalse));
                    if (ch == 0) return false;
                    if (ch != 'H') {
                        shutdownParser();
                        throw new BadRequest("Http version started with illegal character: " + ch);
                    }
                    putChar(ch);
                     = .;
                case :
                    for(ch = next(infalse); ch != .ch = next(infalse)) {
                        if (ch == 0) return false;
                        putChar(ch);
                    }
                    int _majorversion = 1;
                    int _minorversion = 1;
                    if (arrayMatches() || arrayMatches()) {
                    // NOOP, already set to this
//                        _majorversion = 1;
//                        _minorversion = 1;
                    }
                    else if (arrayMatches() || arrayMatches()) {
                        _minorversion = 0;
                    }
                    else {
                        String reason =  "Bad HTTP version: " + getString();
                        clearBuffer();
                        shutdownParser();
                        throw new BadRequest(reason);
                    }
                    String scheme = getString(bufferPosition() - 4);
                    clearBuffer();
                    // We are through parsing the request line
                     = .;
                    return !submitRequestLine(scheme_majorversion_minorversion);
                default:
                    throw new InvalidState("Attempted to parse Request line when already complete." +
                                                  "LineState: '" +  + "'");
            }    // switch
        }        // while loop
    }
New to GrepCode? Check out our FAQ X