src/jdk.httpserver/share/classes/com/sun/net/httpserver/HttpExchange.java
author lancea
Mon, 28 Oct 2019 13:17:54 -0400
changeset 58822 9d95d8a8b750
parent 57981 c4ec55644b4b
permissions -rw-r--r--
8232879: Writing out data with the Zip File System leads to a CRC failure Reviewed-by: lancea, clanger Contributed-by: Jaikiran Pai <jai.forums2013@gmail.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53720
3e451bff6f7f 8218554: HttpServer: allow custom handlers to request that the connection be closed after the exchange.
dfuchs
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.net.httpserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.channels.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class encapsulates a HTTP request received and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * response to be generated in one exchange. It provides methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * for examining the request from the client, and for building and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * sending the response.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The typical life-cycle of a HttpExchange is shown in the sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <ol><li>{@link #getRequestMethod()} to determine the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <li>{@link #getRequestHeaders()} to examine the request headers (if needed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <li>{@link #getRequestBody()} returns a {@link java.io.InputStream} for reading the request body.
54147
8f91e1a7ebdc 8213912: Semantic typo in HttpExchange.java
chegar
parents: 53720
diff changeset
    46
 *     After reading the request body, the stream should be closed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <li>{@link #getResponseHeaders()} to set any response headers, except content-length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <li>{@link #sendResponseHeaders(int,long)} to send the response headers. Must be called before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * next step.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <li>{@link #getResponseBody()} to get a {@link java.io.OutputStream} to send the response body.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      When the response body has been written, the stream must be closed to terminate the exchange.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <b>Terminating exchanges</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Exchanges are terminated when both the request InputStream and response OutputStream are closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Closing the OutputStream, implicitly closes the InputStream (if it is not already closed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * However, it is recommended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * to consume all the data from the InputStream before closing it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * The convenience method {@link #close()} does all of these tasks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Closing an exchange without consuming all of the request body is not an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * but may make the underlying TCP connection unusable for following exchanges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * The effect of failing to terminate an exchange is undefined, but will typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * result in resources failing to be freed/reused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
57981
c4ec55644b4b 8229235: com.sun.net.httpserver.HttpExchange should implement AutoCloseable
michaelm
parents: 54147
diff changeset
    67
public abstract class HttpExchange implements AutoCloseable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected HttpExchange () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Returns an immutable Map containing the HTTP headers that were
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * included with this request. The keys in this Map will be the header
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * names, while the values will be a List of Strings containing each value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * that was included (either for a header that was listed several times,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * or one that accepts a comma-delimited list of values on a single line).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * In either of these cases, the values for the header name will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * presented in the order that they were included in the request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * The keys in Map are case-insensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @return a read-only Map which can be used to access request headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public abstract Headers getRequestHeaders () ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Returns a mutable Map into which the HTTP response headers can be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * and which will be transmitted as part of this response. The keys in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Map will be the header names, while the values must be a List of Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * containing each value that should be included multiple times
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * (in the order that they should be included).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * The keys in Map are case-insensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @return a writable Map which can be used to set response headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public abstract Headers getResponseHeaders () ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Get the request URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @return the request URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public abstract URI getRequestURI () ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Get the request method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return the request method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public abstract String getRequestMethod ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Get the HttpContext for this exchange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @return the HttpContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public abstract HttpContext getHttpContext ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   118
     * Ends this exchange by doing the following in sequence:<ol>
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   119
     * <li>close the request InputStream, if not already closed;</li>
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   120
     * <li>close the response OutputStream, if not already closed.</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public abstract void close () ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * returns a stream from which the request body can be read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Multiple calls to this method will return the same stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * It is recommended that applications should consume (read) all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * data from this stream before closing it. If a stream is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * before all data has been read, then the close() call will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * read and discard remaining data (up to an implementation specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * number of bytes).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the stream from which the request body can be read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public abstract InputStream getRequestBody () ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * returns a stream to which the response body must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * written. {@link #sendResponseHeaders(int,long)}) must be called prior to calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * this method. Multiple calls to this method (for the same exchange)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * will return the same stream. In order to correctly terminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * each exchange, the output stream must be closed, even if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * response body is being sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Closing this stream implicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * closes the InputStream returned from {@link #getRequestBody()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * (if it is not already closed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * If the call to sendResponseHeaders() specified a fixed response
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * body length, then the exact number of bytes specified in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * call must be written to this stream. If too many bytes are written,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * then write() will throw an IOException. If too few bytes are written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * then the stream close() will throw an IOException. In both cases,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * the exchange is aborted and the underlying TCP connection closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @return the stream to which the response body is written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public abstract OutputStream getResponseBody () ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Starts sending the response back to the client using the current set of response headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * and the numeric response code as specified in this method. The response body length is also specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * as follows. If the response length parameter is greater than zero, this specifies an exact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * number of bytes to send and the application must send that exact amount of data.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   165
     * If the response length parameter is {@code zero}, then chunked transfer encoding is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * used and an arbitrary amount of data may be sent. The application terminates the
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   167
     * response body by closing the OutputStream. If response length has the value {@code -1}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * then no response body is being sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * If the content-length response header has not already been set then
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20742
diff changeset
   171
     * this is set to the appropriate value depending on the response length parameter.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * This method must be called prior to calling {@link #getResponseBody()}.
53720
3e451bff6f7f 8218554: HttpServer: allow custom handlers to request that the connection be closed after the exchange.
dfuchs
parents: 47216
diff changeset
   174
     *
3e451bff6f7f 8218554: HttpServer: allow custom handlers to request that the connection be closed after the exchange.
dfuchs
parents: 47216
diff changeset
   175
     * @implNote This implementation allows the caller to instruct the
3e451bff6f7f 8218554: HttpServer: allow custom handlers to request that the connection be closed after the exchange.
dfuchs
parents: 47216
diff changeset
   176
     * server to force a connection close after the exchange terminates, by
3e451bff6f7f 8218554: HttpServer: allow custom handlers to request that the connection be closed after the exchange.
dfuchs
parents: 47216
diff changeset
   177
     * supplying a {@code Connection: close} header to the {@linkplain
3e451bff6f7f 8218554: HttpServer: allow custom handlers to request that the connection be closed after the exchange.
dfuchs
parents: 47216
diff changeset
   178
     * #getResponseHeaders() response headers} before {@code sendResponseHeaders}
3e451bff6f7f 8218554: HttpServer: allow custom handlers to request that the connection be closed after the exchange.
dfuchs
parents: 47216
diff changeset
   179
     * is called.
3e451bff6f7f 8218554: HttpServer: allow custom handlers to request that the connection be closed after the exchange.
dfuchs
parents: 47216
diff changeset
   180
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param rCode the response code to send
30797
9cf3d0361db4 8040147: minor cleanup for docs
avstepan
parents: 30042
diff changeset
   182
     * @param responseLength if {@literal > 0}, specifies a fixed response
9cf3d0361db4 8040147: minor cleanup for docs
avstepan
parents: 30042
diff changeset
   183
     *        body length and that exact number of bytes must be written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *        to the stream acquired from getResponseBody(), or else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *        if equal to 0, then chunked encoding is used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *        and an arbitrary number of bytes may be written.
30797
9cf3d0361db4 8040147: minor cleanup for docs
avstepan
parents: 30042
diff changeset
   187
     *        if {@literal <= -1}, then no response body length is specified and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *        no response body may be written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see HttpExchange#getResponseBody()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public abstract void sendResponseHeaders (int rCode, long responseLength) throws IOException ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Returns the address of the remote entity invoking this request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @return the InetSocketAddress of the caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public abstract InetSocketAddress getRemoteAddress ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns the response code, if it has already been set
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   201
     * @return the response code, if available. {@code -1} if not available yet.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public abstract int getResponseCode ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Returns the local address on which the request was received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @return the InetSocketAddress of the local interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public abstract InetSocketAddress getLocalAddress ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Returns the protocol string from the request in the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <i>protocol/majorVersion.minorVersion</i>. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * "HTTP/1.1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return the protocol string from the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public abstract String getProtocol ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Filter modules may store arbitrary objects with HttpExchange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * instances as an out-of-band communication mechanism. Other Filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * or the exchange handler may then access these objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Each Filter class will document the attributes which they make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param name the name of the attribute to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return the attribute object, or null if it does not exist
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   228
     * @throws NullPointerException if name is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public abstract Object getAttribute (String name) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Filter modules may store arbitrary objects with HttpExchange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * instances as an out-of-band communication mechanism. Other Filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * or the exchange handler may then access these objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Each Filter class will document the attributes which they make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param name the name to associate with the attribute value
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   240
     * @param value the object to store as the attribute value. {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * value is permitted.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   242
     * @throws NullPointerException if name is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public abstract void setAttribute (String name, Object value) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Used by Filters to wrap either (or both) of this exchange's InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * and OutputStream, with the given filtered streams so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * that subsequent calls to {@link #getRequestBody()} will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * return the given {@link java.io.InputStream}, and calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * {@link #getResponseBody()} will return the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * {@link java.io.OutputStream}. The streams provided to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * call must wrap the original streams, and may be (but are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * required to be) sub-classes of {@link java.io.FilterInputStream}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * and {@link java.io.FilterOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param i the filtered input stream to set as this object's inputstream,
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   257
     *          or {@code null} if no change.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param o the filtered output stream to set as this object's outputstream,
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   259
     *          or {@code null} if no change.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public abstract void setStreams (InputStream i, OutputStream o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * If an authenticator is set on the HttpContext that owns this exchange,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * then this method will return the {@link HttpPrincipal} that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * the authenticated user for this HttpExchange.
30042
4728ebcf8fd0 8076224: some tidy warnings from core libs
avstepan
parents: 29109
diff changeset
   268
     * @return the HttpPrincipal, or {@code null} if no authenticator is set.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public abstract HttpPrincipal getPrincipal ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
}