001/*
002 * ====================================================================
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 * ====================================================================
020 *
021 * This software consists of voluntary contributions made by many
022 * individuals on behalf of the Apache Software Foundation.  For more
023 * information on the Apache Software Foundation, please see
024 * <http://www.apache.org/>.
025 *
026 */
027
028package org.apache.http;
029
030import java.io.IOException;
031
032/**
033 * A server-side HTTP connection, which can be used for receiving
034 * requests and sending responses.
035 *
036 * @since 4.0
037 */
038public interface HttpServerConnection extends HttpConnection {
039
040    /**
041     * Receives the request line and all headers available from this connection.
042     * The caller should examine the returned request and decide if to receive a
043     * request entity as well.
044     *
045     * @return a new HttpRequest object whose request line and headers are
046     *         initialized.
047     * @throws HttpException in case of HTTP protocol violation
048     * @throws IOException in case of an I/O error
049     */
050    HttpRequest receiveRequestHeader()
051        throws HttpException, IOException;
052
053    /**
054     * Receives the next request entity available from this connection and attaches it to
055     * an existing request.
056     * @param request the request to attach the entity to.
057     * @throws HttpException in case of HTTP protocol violation
058     * @throws IOException in case of an I/O error
059     */
060    void receiveRequestEntity(HttpEntityEnclosingRequest request)
061        throws HttpException, IOException;
062
063    /**
064     * Sends the response line and headers of a response over this connection.
065     * @param response the response whose headers to send.
066     * @throws HttpException in case of HTTP protocol violation
067     * @throws IOException in case of an I/O error
068     */
069    void sendResponseHeader(HttpResponse response)
070        throws HttpException, IOException;
071
072    /**
073     * Sends the response entity of a response over this connection.
074     * @param response the response whose entity to send.
075     * @throws HttpException in case of HTTP protocol violation
076     * @throws IOException in case of an I/O error
077     */
078    void sendResponseEntity(HttpResponse response)
079        throws HttpException, IOException;
080
081    /**
082     * Sends all pending buffered data over this connection.
083     * @throws IOException in case of an I/O error
084     */
085    void flush()
086        throws IOException;
087
088}