Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.http4s.blaze.http.http_parser;
  
  
  public abstract class Http1ClientParser extends BodyAndHeaderParser {
  
      public Http1ClientParser(int maxRequestLineSizeint maxHeaderLengthint initialBufferSizeint maxChunkSize) {
          super(initialBufferSizemaxHeaderLengthmaxChunkSize);
         this. = maxRequestLineSize;
 
         _internalReset();
     }
 
     public Http1ClientParser(int initialBufferSize) {
         this(2048, 40*1024, initialBufferSize.);
     }
 
     public Http1ClientParser() {
         this(10*1024);
     }
 
     // Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
     private enum RequestLineState {
         START,
         VERSION,
         SPACE1,
         STATUS_CODE,
         SPACE2,
         REASON,
         END,
     }
 
     private final int maxRequestLineSize;
 
     private String _lineScheme = null;
     private int _majorVersion = 0;
     private int _minorVersion = 0;
     private int _statusCode = 0;
 
     final public boolean isStartState() {
         return  == .;
     }
 
     protected abstract void submitResponseLine(int codeString reasonString schemeint majorversionint minorversion);
 
     public final boolean responseLineComplete() {
         return  == .;
     }
 
     @Override
     public void shutdownParser() {
         super.shutdownParser();    //To change body of overridden methods use File | Settings | File Templates.
     }
 
     @Override
     public void reset() {
         super.reset();
         _internalReset();
     }
 
     private void _internalReset() {
          = null;
          = 0;
          = 0;
          = 0;
     }
 
     @Override
     public boolean mayHaveBody() {
         return contentComplete() ||
             ( >= 200 &&
               != 204 &&
               != 304);
     }

    
parses the request line. Returns true if completed successfully, false if needs input
 
     protected final boolean parseResponseLine(ByteBuffer inthrows BaseExceptions.InvalidStateBaseExceptions.BadResponse {
         try {
             lineLoop: while(true) {
                 char ch;
                 switch () {
                     case :
                          = .;
                         resetLimit();
 
                     case :
                         for(ch = next(infalse); ch != . && ch != .ch = next(infalse)) {
                             if (ch == 0) return false;
                             putChar(ch);
                         }
 
                          = 1;
                          = 1;
 
                         if (arrayMatches() || arrayMatches(.)) {
                             = 1;
                             = 1;
                        }
                        else if (arrayMatches() || arrayMatches()) {
                             = 1;
                             = 0;
                        }
                        else {
                            String reason =  "Bad HTTP version: " + getString();
                            clearBuffer();
                            shutdownParser();
                            throw new BadResponse(reason);
                        }
                         = getString(bufferPosition() - 4);
                        clearBuffer();
                        // We are through parsing the request line
                         = .;
                    case :
                        // Eat whitespace
                        for(ch = next(infalse); ch == . || ch == .ch = next(infalse));
                        if (ch == 0) return false;
                        if (!HttpTokens.isDigit(ch)) {
                            shutdownParser();
                            throw new BadResponse("Received invalid token when needed code: '" + (char)ch + "'");
                        }
                         = 10* + (ch - .);
                         = .;
                    case :
                        for(ch = next(infalse); HttpTokens.isDigit(ch); ch = next(infalse)) {
                            if (ch == 0) return false;
                             = 10* + (ch - .);
                        }
                        if (ch == 0) return false;  // Need more data
                        if (!HttpTokens.isWhiteSpace(ch)) {
                            shutdownParser();
                            throw new BadResponse("Invalid request: Expected SPACE but found '" + (char)ch + "'");
                        }
                        if ( < 100 ||  >= 600) {
                            shutdownParser();
                            throw new BadResponse("Invalid status code '" +
                                     + "'. Must be between 100 and 599");
                        }
                         = .;
                    case :
                        // Eat whitespace
                        for(ch = next(infalse); ch == . || ch == .ch = next(infalse));
                        if (ch == 0) return false;
                        if (ch == .) {
                            shutdownParser();
                            throw new BadResponse("Response lacks status Reason");
                        }
                        putChar(ch);
                         = .;
                    case :
                        for(ch = next(infalse); ch != .ch = next(infalse)) {
                            if (ch == 0) return false;
                            putChar(ch);
                        }
                        String reason = getTrimmedString();
                        clearBuffer();
                        // We are through parsing the request line
                         = .;
                        submitResponseLine(reason);
                        return true;
                    default:
                        throw new BaseExceptions.InvalidState("Attempted to parse Response line when already complete." +
                                "RequestLineState: '" +  + "'");
                }    // switch
            }        // while loop
        } catch (BaseExceptions.BadRequest ex) {
            shutdownParser();
            throw new BadResponse(ex.getMessage());
        }
    }
New to GrepCode? Check out our FAQ X