|
30 | 30 | import org.takes.misc.Href;
|
31 | 31 |
|
32 | 32 | /**
|
33 |
| - * Request decorator, for HTTP URI query parsing. |
| 33 | + * HTTP URI query parsing. |
34 | 34 | *
|
35 |
| - * <p>The class is immutable and thread-safe. |
| 35 | + * <p>All implementations of this interface must be immutable and thread-safe. |
36 | 36 | *
|
37 | 37 | * @author Yegor Bugayenko ([email protected])
|
38 | 38 | * @version $Id$
|
39 | 39 | * @since 0.9
|
40 | 40 | */
|
41 |
| -@EqualsAndHashCode(callSuper = true) |
42 |
| -public final class RqHref extends RqWrap { |
43 |
| - |
44 |
| - /** |
45 |
| - * Ctor. |
46 |
| - * @param req Original request |
47 |
| - */ |
48 |
| - public RqHref(final Request req) { |
49 |
| - super(req); |
50 |
| - } |
51 |
| - |
| 41 | +public interface RqHref extends Request { |
52 | 42 | /**
|
53 | 43 | * Get HREF.
|
54 | 44 | * @return HTTP href
|
55 | 45 | * @throws IOException If fails
|
56 | 46 | */
|
57 |
| - public Href href() throws IOException { |
58 |
| - final Iterator<String> host = new RqHeaders(this) |
59 |
| - .header("Host").iterator(); |
60 |
| - if (!host.hasNext()) { |
61 |
| - throw new IOException("Host header is absent"); |
| 47 | + Href href() throws IOException; |
| 48 | + |
| 49 | + /** |
| 50 | + * Request decorator, for HTTP URI query parsing. |
| 51 | + * |
| 52 | + * <p>The class is immutable and thread-safe. |
| 53 | + * @author Dmitry Zaytsev ([email protected]) |
| 54 | + * @version $Id$ |
| 55 | + * @since 0.13.1 |
| 56 | + */ |
| 57 | + @EqualsAndHashCode(callSuper = true) |
| 58 | + final class Base extends RqWrap implements RqHref { |
| 59 | + /** |
| 60 | + * Ctor. |
| 61 | + * @param req Original request |
| 62 | + */ |
| 63 | + public Base(final Request req) { |
| 64 | + super(req); |
| 65 | + }; |
| 66 | + |
| 67 | + @Override |
| 68 | + public Href href() throws IOException { |
| 69 | + final Iterator<String> host = new RqHeaders(this) |
| 70 | + .header("Host").iterator(); |
| 71 | + if (!host.hasNext()) { |
| 72 | + throw new IOException("Host header is absent"); |
| 73 | + } |
| 74 | + return new Href( |
| 75 | + String.format( |
| 76 | + "http://%s%s", |
| 77 | + host.next(), |
| 78 | + // @checkstyle MagicNumber (1 line) |
| 79 | + this.head().iterator().next().split(" ", 3)[1] |
| 80 | + ) |
| 81 | + ); |
62 | 82 | }
|
63 |
| - return new Href( |
64 |
| - String.format( |
65 |
| - "http://%s%s", |
66 |
| - host.next(), |
67 |
| - // @checkstyle MagicNumber (1 line) |
68 |
| - this.head().iterator().next().split(" ", 3)[1] |
69 |
| - ) |
70 |
| - ); |
71 | 83 | }
|
72 |
| - |
73 | 84 | }
|
| 85 | + |
0 commit comments