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