Skip to content

Commit 4391f22

Browse files
committed
Merge remote branch 'fork/139'
2 parents c149713 + 7bb34ae commit 4391f22

17 files changed

+61
-50
lines changed

src/main/java/org/takes/facets/auth/PsByFlag.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public PsByFlag(final String flg, final Map<String, Pass> map) {
9898

9999
@Override
100100
public Iterator<Identity> enter(final Request req) throws IOException {
101-
final Iterator<String> flg = new RqHref(req).href()
101+
final Iterator<String> flg = new RqHref.Base(req).href()
102102
.param(this.flag).iterator();
103103
final Collection<Identity> users = new ArrayList<Identity>(1);
104104
if (flg.hasNext()) {

src/main/java/org/takes/facets/auth/XeLogoutLink.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public XeLogoutLink(final Request req, final String rel,
6464
super(
6565
new XeLink(
6666
rel,
67-
new RqHref(req).href().with(
67+
new RqHref.Base(req).href().with(
6868
flag, PsLogout.class.getSimpleName()
6969
).toString()
7070
)

src/main/java/org/takes/facets/auth/social/PsFacebook.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public PsFacebook(final String fapp, final String fkey) {
7878
@Override
7979
public Iterator<Identity> enter(final Request request)
8080
throws IOException {
81-
final Href href = new RqHref(request).href();
81+
final Href href = new RqHref.Base(request).href();
8282
final Iterator<String> code = href.param("code").iterator();
8383
if (!code.hasNext()) {
8484
throw new IllegalArgumentException("code is not provided");

src/main/java/org/takes/facets/auth/social/PsGithub.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public PsGithub(final String gapp, final String gkey) {
7878
@Override
7979
public Iterator<Identity> enter(final Request request)
8080
throws IOException {
81-
final Href href = new RqHref(request).href();
81+
final Href href = new RqHref.Base(request).href();
8282
final Iterator<String> code = href.param("code").iterator();
8383
if (!code.hasNext()) {
8484
throw new IllegalArgumentException("code is not provided");

src/main/java/org/takes/facets/auth/social/PsGoogle.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public PsGoogle(final String gapp, final String gkey) {
7575
@Override
7676
public Iterator<Identity> enter(final Request request)
7777
throws IOException {
78-
final Href href = new RqHref(request).href();
78+
final Href href = new RqHref.Base(request).href();
7979
final Iterator<String> code = href.param("code").iterator();
8080
if (!code.hasNext()) {
8181
throw new IllegalArgumentException("code is not provided");

src/main/java/org/takes/facets/auth/social/PsLinkedin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public PsLinkedin(final String lapp, final String lkey) {
7575
@Override
7676
public Iterator<Identity> enter(final Request request)
7777
throws IOException {
78-
final Href href = new RqHref(request).href();
78+
final Href href = new RqHref.Base(request).href();
7979
// @checkstyle MultipleStringLiteralsCheck (1 line)
8080
final Iterator<String> code = href.param("code").iterator();
8181
if (!code.hasNext()) {

src/main/java/org/takes/facets/auth/social/XeFacebookLink.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public XeFacebookLink(final Request req, final String app, final String rel,
7373
.with("client_id", app)
7474
.with(
7575
"redirect_uri",
76-
new RqHref(req).href()
76+
new RqHref.Base(req).href()
7777
.with(flag, PsFacebook.class.getSimpleName())
7878
.toString()
7979
)

src/main/java/org/takes/facets/auth/social/XeGithubLink.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public XeGithubLink(final Request req, final String app, final String rel,
7373
.with("client_id", app)
7474
.with(
7575
"redirect_uri",
76-
new RqHref(req).href()
76+
new RqHref.Base(req).href()
7777
.with(flag, PsGithub.class.getSimpleName())
7878
.toString()
7979
)

src/main/java/org/takes/facets/auth/social/XeGoogleLink.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public XeGoogleLink(final Request req, final String app, final String rel,
7373
.with("client_id", app)
7474
.with(
7575
"redirect_uri",
76-
new RqHref(req).href()
76+
new RqHref.Base(req).href()
7777
.with(flag, PsGoogle.class.getSimpleName())
7878
.toString()
7979
)

src/main/java/org/takes/facets/fork/FkParams.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public FkParams(final String param, final Pattern ptn, final Take tke) {
8686

8787
@Override
8888
public Iterator<Response> route(final Request req) throws IOException {
89-
final Iterator<String> params = new RqHref(req).href()
89+
final Iterator<String> params = new RqHref.Base(req).href()
9090
.param(this.name).iterator();
9191
final Collection<Response> list = new ArrayList<Response>(1);
9292
if (params.hasNext()

src/main/java/org/takes/facets/fork/FkRegex.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public FkRegex(final Pattern ptn, final TkRegex tgt) {
152152
@Override
153153
public Iterator<Response> route(final Request req) throws IOException {
154154
final Matcher matcher = this.pattern.matcher(
155-
new RqHref(req).href().path()
155+
new RqHref.Base(req).href().path()
156156
);
157157
final Collection<Response> list = new ArrayList<Response>(1);
158158
if (matcher.matches()) {

src/main/java/org/takes/rq/RqHref.java

+39-27
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,56 @@
3030
import org.takes.misc.Href;
3131

3232
/**
33-
* Request decorator, for HTTP URI query parsing.
33+
* HTTP URI query parsing.
3434
*
35-
* <p>The class is immutable and thread-safe.
35+
* <p>All implementations of this interface must be immutable and thread-safe.
3636
*
3737
* @author Yegor Bugayenko ([email protected])
3838
* @version $Id$
3939
* @since 0.9
4040
*/
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 {
5242
/**
5343
* Get HREF.
5444
* @return HTTP href
5545
* @throws IOException If fails
5646
*/
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+
);
6282
}
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-
);
7183
}
72-
7384
}
85+

src/main/java/org/takes/rs/xe/XeLinkSelf.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public XeLinkSelf(final Request req) {
5252
public Iterable<Directive> toXembly() throws IOException {
5353
return new XeLink(
5454
"self",
55-
new RqHref(req).href().toString()
55+
new RqHref.Base(req).href().toString()
5656
).toXembly();
5757
}
5858
}

src/main/java/org/takes/tk/TkClasspath.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public TkClasspath(final String prefix) {
8989
@Override
9090
public Response act(final Request request) throws IOException {
9191
final String name = String.format(
92-
"%s%s", prefix, new RqHref(request).href().path()
92+
"%s%s", prefix, new RqHref.Base(request).href().path()
9393
);
9494
final InputStream input = this.getClass()
9595
.getResourceAsStream(name);

src/main/java/org/takes/tk/TkFiles.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public TkFiles(final File base) {
7979
@Override
8080
public Response act(final Request request) throws IOException {
8181
final File file = new File(
82-
base, new RqHref(request).href().path()
82+
base, new RqHref.Base(request).href().path()
8383
);
8484
if (!file.exists()) {
8585
throw new HttpException(

src/main/java/org/takes/tk/TkVerbose.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Response act(final Request request) throws IOException {
6161
String.format(
6262
"%s %s",
6363
new RqMethod(request).method(),
64-
new RqHref(request).href()
64+
new RqHref.Base(request).href()
6565
),
6666
ex
6767
);

src/test/java/org/takes/rq/RqHrefTest.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
import org.junit.Test;
3131

3232
/**
33-
* Test case for {@link RqHref}.
33+
* Test case for {@link RqHref.Base}.
3434
* @author Yegor Bugayenko ([email protected])
3535
* @version $Id$
3636
* @since 0.1
3737
*/
3838
public final class RqHrefTest {
3939

4040
/**
41-
* RqQuery can parse a query.
41+
* RqHref.Base can parse a query.
4242
* @throws IOException If some problem inside
4343
*/
4444
@Test
4545
public void parsesHttpQuery() throws IOException {
4646
MatcherAssert.assertThat(
47-
new RqHref(
47+
new RqHref.Base(
4848
new RqFake(
4949
Arrays.asList(
5050
"GET /h?a=3",
@@ -59,13 +59,13 @@ public void parsesHttpQuery() throws IOException {
5959
}
6060

6161
/**
62-
* RqQuery can extract params.
62+
* RqHref.Base can extract params.
6363
* @throws IOException If some problem inside
6464
*/
6565
@Test
6666
public void extractsParams() throws IOException {
6767
MatcherAssert.assertThat(
68-
new RqHref(
68+
new RqHref.Base(
6969
new RqFake(
7070
Arrays.asList(
7171
"GET /hello?a=3&b=7&c&d=9%28x%29&ff",
@@ -80,13 +80,13 @@ public void extractsParams() throws IOException {
8080
}
8181

8282
/**
83-
* RqQuery can extract first params.
83+
* RqHref.Base can extract first params.
8484
* @throws IOException If some problem inside
8585
*/
8686
@Test
8787
public void extractsFirstParam() throws IOException {
8888
MatcherAssert.assertThat(
89-
new RqHref(
89+
new RqHref.Base(
9090
new RqFake(
9191
Arrays.asList(
9292
"GET /hello?since=343",
@@ -98,5 +98,4 @@ public void extractsFirstParam() throws IOException {
9898
Matchers.hasItem("343")
9999
);
100100
}
101-
102101
}

0 commit comments

Comments
 (0)