View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.mina.http.api;
21  
22  import java.util.Map;
23  
24  public class DefaultHttpResponse implements HttpResponse {
25  
26      private final HttpVersion version;
27  
28      private final HttpStatus status;
29  
30      private final Map<String, String> headers;
31  
32      public DefaultHttpResponse(HttpVersion version, HttpStatus status, Map<String, String> headers) {
33          this.version = version;
34          this.status = status;
35          this.headers = headers;
36      }
37  
38      public HttpVersion getProtocolVersion() {
39          return version;
40      }
41  
42      public String getContentType() {
43          return headers.get("content-type");
44      }
45  
46      public boolean isKeepAlive() {
47          // TODO check header and version for keep alive
48          return false;
49      }
50  
51      public String getHeader(String name) {
52          return headers.get(name);
53      }
54  
55      public boolean containsHeader(String name) {
56          return headers.containsKey(name);
57      }
58  
59      public Map<String, String> getHeaders() {
60          return headers;
61      }
62  
63      public HttpStatus getStatus() {
64          return status;
65      }
66  
67      @Override
68      public String toString() {
69          String result = "HTTP RESPONSE STATUS: " + status + "\n";
70          result += "VERSION: " + version + "\n";
71  
72          result += "--- HEADER --- \n";
73          for (String key : headers.keySet()) {
74              String value = headers.get(key);
75              result += key + ":" + value + "\n";
76          }
77  
78          return result;
79      }
80  }