1 //
2 // ========================================================================
3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19
20 package org.eclipse.jetty.http;
21
22 import org.eclipse.jetty.util.HostPort;
23
24
25
26 /* ------------------------------------------------------------ */
27 /**
28 */
29 public class HostPortHttpField extends HttpField
30 {
31 final HostPort _hostPort;
32
33 public HostPortHttpField(String authority)
34 {
35 this(HttpHeader.HOST,HttpHeader.HOST.asString(),authority);
36 }
37
38 /* ------------------------------------------------------------ */
39 protected HostPortHttpField(HttpHeader header, String name, String authority)
40 {
41 super(header,name,authority);
42 try
43 {
44 _hostPort=new HostPort(authority);
45 }
46 catch(Exception e)
47 {
48 throw new BadMessageException(HttpStatus.BAD_REQUEST_400,"Bad HostPort",e);
49 }
50 }
51
52 /* ------------------------------------------------------------ */
53 /** Get the host.
54 * @return the host
55 */
56 public String getHost()
57 {
58 return _hostPort.getHost();
59 }
60
61 /* ------------------------------------------------------------ */
62 /** Get the port.
63 * @return the port
64 */
65 public int getPort()
66 {
67 return _hostPort.getPort();
68 }
69
70 /* ------------------------------------------------------------ */
71 /** Get the port.
72 * @param defaultPort The default port to return if no port set
73 * @return the port
74 */
75 public int getPort(int defaultPort)
76 {
77 return _hostPort.getPort(defaultPort);
78 }
79 }