001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.mina.proxy.handlers.http;
021
022import java.util.List;
023import java.util.Map;
024
025/**
026 * HttpProxyResponse.java - Wrapper class for HTTP requests.
027 * 
028 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
029 * @since MINA 2.0.0-M3
030 */
031public class HttpProxyResponse {
032    /**
033     * The HTTP response protocol version.
034     */
035    private final String httpVersion;
036
037    /**
038     * The HTTP response status line.
039     */
040    private final String statusLine;
041
042    /**
043     * The HTTP response status code;
044     */
045    private final int statusCode;
046
047    /**
048     * The HTTP response headers.
049     */
050    private final Map<String, List<String>> headers;
051
052    /**
053     * The HTTP response body.
054     */
055    private String body;
056
057    /**
058     * Constructor of an HTTP proxy response.
059     *  
060     * @param httpVersion the protocol version
061     * @param statusLine the response status line
062     * @param headers the response headers
063     */
064    protected HttpProxyResponse(final String httpVersion, final String statusLine,
065            final Map<String, List<String>> headers) {
066        this.httpVersion = httpVersion;
067        this.statusLine = statusLine;
068
069        // parses the status code from the status line
070        this.statusCode = statusLine.charAt(0) == ' ' ? Integer.parseInt(statusLine.substring(1, 4)) : Integer
071                .parseInt(statusLine.substring(0, 3));
072
073        this.headers = headers;
074    }
075
076    /**
077     * @return the HTTP response protocol version.
078     */
079    public final String getHttpVersion() {
080        return httpVersion;
081    }
082
083    /**
084     * @return the HTTP response status code.
085     */
086    public final int getStatusCode() {
087        return statusCode;
088    }
089
090    /**
091     * @return the HTTP response status line.
092     */
093    public final String getStatusLine() {
094        return statusLine;
095    }
096
097    /**
098     * @return the HTTP response body.
099     */
100    public String getBody() {
101        return body;
102    }
103
104    /**
105     * Sets the HTTP response body.
106     * 
107     * @param body The HTTP Body
108     */
109    public void setBody(String body) {
110        this.body = body;
111    }
112
113    /**
114     * @return the HTTP response headers.
115     */
116    public final Map<String, List<String>> getHeaders() {
117        return headers;
118    }
119}