/** * Parses the HTTP request produced by the given stream. * * @param inputStream producing a HTTP request * @param senderAddress the address of the request sender, if known * @return a parsed HTTP request object * @throws InvalidHttpRequest if the request is invalid * @throws IOException if a problem occurs accessing the stream */ public RawHttpRequest parseRequest(InputStream inputStream, @Nullable InetAddress senderAddress) throws IOException { RequestLine requestLine = metadataParser.parseRequestLine(inputStream); RawHttpHeaders originalHeaders = metadataParser.parseHeaders(inputStream, (message, lineNumber) -> // add 1 to the line number to correct for the start-line new InvalidHttpRequest(message, lineNumber + 1)); RawHttpHeaders.Builder modifiableHeaders = RawHttpHeaders.newBuilder(originalHeaders); // do a little cleanup to make sure the request is actually valid requestLine = verifyHost(requestLine, modifiableHeaders); RawHttpHeaders headers = modifiableHeaders.build(); @Nullable BodyReader bodyReader = requestHasBody(headers) ? createBodyReader(inputStream, requestLine, headers) : null; return new RawHttpRequest(requestLine, headers, bodyReader, senderAddress); }
/** * Parses the HTTP request produced by the given stream. * * @param inputStream producing a HTTP request * @param senderAddress the address of the request sender, if known * @return a parsed HTTP request object * @throws InvalidHttpRequest if the request is invalid * @throws IOException if a problem occurs accessing the stream */ public RawHttpRequest parseRequest(InputStream inputStream, @Nullable InetAddress senderAddress) throws IOException { RequestLine requestLine = metadataParser.parseRequestLine(inputStream); RawHttpHeaders originalHeaders = metadataParser.parseHeaders(inputStream, (message, lineNumber) -> // add 1 to the line number to correct for the start-line new InvalidHttpRequest(message, lineNumber + 1)); RawHttpHeaders.Builder modifiableHeaders = RawHttpHeaders.newBuilder(originalHeaders); // do a little cleanup to make sure the request is actually valid requestLine = verifyHost(requestLine, modifiableHeaders); RawHttpHeaders headers = modifiableHeaders.build(); @Nullable BodyReader bodyReader = requestHasBody(headers) ? createBodyReader(inputStream, requestLine, headers) : null; return new RawHttpRequest(requestLine, headers, bodyReader, senderAddress); }