michael@0: /*
michael@0: * ====================================================================
michael@0: * Licensed to the Apache Software Foundation (ASF) under one
michael@0: * or more contributor license agreements. See the NOTICE file
michael@0: * distributed with this work for additional information
michael@0: * regarding copyright ownership. The ASF licenses this file
michael@0: * to you under the Apache License, Version 2.0 (the
michael@0: * "License"); you may not use this file except in compliance
michael@0: * with the License. You may obtain a copy of the License at
michael@0: *
michael@0: * http://www.apache.org/licenses/LICENSE-2.0
michael@0: *
michael@0: * Unless required by applicable law or agreed to in writing,
michael@0: * software distributed under the License is distributed on an
michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0: * KIND, either express or implied. See the License for the
michael@0: * specific language governing permissions and limitations
michael@0: * under the License.
michael@0: * ====================================================================
michael@0: *
michael@0: * This software consists of voluntary contributions made by many
michael@0: * individuals on behalf of the Apache Software Foundation. For more
michael@0: * information on the Apache Software Foundation, please see
michael@0: * .
michael@0: *
michael@0: */
michael@0:
michael@0: package ch.boye.httpclientandroidlib.message;
michael@0:
michael@0: import ch.boye.httpclientandroidlib.ProtocolVersion;
michael@0: import ch.boye.httpclientandroidlib.ParseException;
michael@0: import ch.boye.httpclientandroidlib.RequestLine;
michael@0: import ch.boye.httpclientandroidlib.StatusLine;
michael@0: import ch.boye.httpclientandroidlib.Header;
michael@0: import ch.boye.httpclientandroidlib.util.CharArrayBuffer;
michael@0:
michael@0: /**
michael@0: * Interface for parsing lines in the HEAD section of an HTTP message.
michael@0: * There are individual methods for parsing a request line, a
michael@0: * status line, or a header line.
michael@0: * The lines to parse are passed in memory, the parser does not depend
michael@0: * on any specific IO mechanism.
michael@0: * Instances of this interface are expected to be stateless and thread-safe.
michael@0: *
michael@0: * @since 4.0
michael@0: */
michael@0: public interface LineParser {
michael@0:
michael@0: /**
michael@0: * Parses the textual representation of a protocol version.
michael@0: * This is needed for parsing request lines (last element)
michael@0: * as well as status lines (first element).
michael@0: *
michael@0: * @param buffer a buffer holding the protocol version to parse
michael@0: * @param cursor the parser cursor containing the current position and
michael@0: * the bounds within the buffer for the parsing operation
michael@0: *
michael@0: * @return the parsed protocol version
michael@0: *
michael@0: * @throws ParseException in case of a parse error
michael@0: */
michael@0: ProtocolVersion parseProtocolVersion(
michael@0: CharArrayBuffer buffer,
michael@0: ParserCursor cursor) throws ParseException;
michael@0:
michael@0: /**
michael@0: * Checks whether there likely is a protocol version in a line.
michael@0: * This method implements a heuristic to check for a
michael@0: * likely protocol version specification. It does not
michael@0: * guarantee that {@link #parseProtocolVersion} would not
michael@0: * detect a parse error.
michael@0: * This can be used to detect garbage lines before a request
michael@0: * or status line.
michael@0: *
michael@0: * @param buffer a buffer holding the line to inspect
michael@0: * @param cursor the cursor at which to check for a protocol version, or
michael@0: * negative for "end of line". Whether the check tolerates
michael@0: * whitespace before or after the protocol version is
michael@0: * implementation dependent.
michael@0: *
michael@0: * @return true
if there is a protocol version at the
michael@0: * argument index (possibly ignoring whitespace),
michael@0: * false
otherwise
michael@0: */
michael@0: boolean hasProtocolVersion(
michael@0: CharArrayBuffer buffer,
michael@0: ParserCursor cursor);
michael@0:
michael@0: /**
michael@0: * Parses a request line.
michael@0: *
michael@0: * @param buffer a buffer holding the line to parse
michael@0: * @param cursor the parser cursor containing the current position and
michael@0: * the bounds within the buffer for the parsing operation
michael@0: *
michael@0: * @return the parsed request line
michael@0: *
michael@0: * @throws ParseException in case of a parse error
michael@0: */
michael@0: RequestLine parseRequestLine(
michael@0: CharArrayBuffer buffer,
michael@0: ParserCursor cursor) throws ParseException;
michael@0:
michael@0: /**
michael@0: * Parses a status line.
michael@0: *
michael@0: * @param buffer a buffer holding the line to parse
michael@0: * @param cursor the parser cursor containing the current position and
michael@0: * the bounds within the buffer for the parsing operation
michael@0: *
michael@0: * @return the parsed status line
michael@0: *
michael@0: * @throws ParseException in case of a parse error
michael@0: */
michael@0: StatusLine parseStatusLine(
michael@0: CharArrayBuffer buffer,
michael@0: ParserCursor cursor) throws ParseException;
michael@0:
michael@0: /**
michael@0: * Creates a header from a line.
michael@0: * The full header line is expected here. Header continuation lines
michael@0: * must be joined by the caller before invoking this method.
michael@0: *
michael@0: * @param buffer a buffer holding the full header line.
michael@0: * This buffer MUST NOT be re-used afterwards, since
michael@0: * the returned object may reference the contents later.
michael@0: *
michael@0: * @return the header in the argument buffer.
michael@0: * The returned object MAY be a wrapper for the argument buffer.
michael@0: * The argument buffer MUST NOT be re-used or changed afterwards.
michael@0: *
michael@0: * @throws ParseException in case of a parse error
michael@0: */
michael@0: Header parseHeader(CharArrayBuffer buffer)
michael@0: throws ParseException;
michael@0:
michael@0: }