1 module hunt.http.codec.http.model.HostPortHttpField;
2 
3 import hunt.http.codec.http.model.BadMessageException;
4 import hunt.http.codec.http.model.HostPort;
5 import hunt.http.HttpField;
6 import hunt.http.HttpHeader;
7 import hunt.http.HttpStatus;
8 
9 import hunt.logging;
10 
11 
12 class HostPortHttpField : HttpField {
13 	private HostPort _hostPort;
14 
15 	this(string authority) {
16 		this(HttpHeader.HOST, HttpHeader.HOST.asString(), authority);
17 	}
18 
19 	this(HttpHeader header, string name, string authority) {
20 		version(HUNT_HTTP_DEBUG)
21 		tracef("name=%s, authority=%s", name, authority);
22 		super(header, name, authority);
23 		try {
24 			_hostPort = new HostPort(authority);
25 		} catch (Exception e) {
26 			throw new BadMessageException(HttpStatus.BAD_REQUEST_400, "Bad HostPort", e);
27 		}
28 	}
29 
30 	/**
31 	 * Get the host.
32 	 * 
33 	 * @return the host
34 	 */
35 	string getHost() {
36 		return _hostPort.getHost();
37 	}
38 
39 	/**
40 	 * Get the port.
41 	 * 
42 	 * @return the port
43 	 */
44 	int getPort() {
45 		return _hostPort.getPort();
46 	}
47 
48 	/**
49 	 * Get the port.
50 	 * 
51 	 * @param defaultPort
52 	 *            The default port to return if no port set
53 	 * @return the port
54 	 */
55 	int getPort(int defaultPort) {
56 		return _hostPort.getPort(defaultPort);
57 	}
58 }