Skip to content

Commit b23b493

Browse files
committed
Add test and fix
1 parent 3ed56c4 commit b23b493

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
<groupId>com.javamonday.xsoup</groupId>
77
<artifactId>xsoup</artifactId>
8-
<version>1.7.3-SNAPSHOT</version>
8+
<version>1.7.4-SNAPSHOT</version>
99
<description>xsoup HTML parser</description>
1010
<url>http://xsoup.org/</url>
1111
<inceptionYear>2009</inceptionYear>
1212
<issueManagement>
1313
<system>GitHub</system>
14-
<url>http://github.com/jhy/jsoup/issues</url>
14+
<url>https://github.com/JavaMonday/xsoup/issues</url>
1515
</issueManagement>
1616
<licenses>
1717
<license>

src/main/java/com/monday/xsoup/Connection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,14 @@ public enum Method {
215215

216216
/**
217217
* Execute the request as a GET, and parse the result.
218-
* @return parsed Document
218+
* @return parsed Header
219219
* @throws java.net.MalformedURLException if the request URL is not a HTTP or HTTPS URL, or is otherwise malformed
220220
* @throws HttpStatusException if the response is not OK and HTTP response errors are not ignored
221221
* @throws UnsupportedMimeTypeException if the response mime type is not supported and those errors are not ignored
222222
* @throws java.net.SocketTimeoutException if the connection times out
223223
* @throws IOException on error
224224
*/
225-
public Document head() throws IOException;
225+
public Map<String, String> head() throws IOException;
226226

227227

228228

src/main/java/com/monday/xsoup/helper/HttpConnection.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ static Response execute(Connection.Request req, Response previousResponse) throw
450450

451451

452452
// set up the request for execution
453-
if (req.method() == Connection.Method.GET && req.data().size() > 0)
453+
if (req.method() == Connection.Method.GET || req.method() == Connection.Method.HEAD && req.data().size() > 0)
454454
serialiseRequestUrl(req); // appends query string
455455
HttpURLConnection conn = createConnection(req);
456456
Response res;
@@ -733,21 +733,28 @@ public String toString() {
733733
}
734734

735735
public Document put() throws IOException {
736-
// TODO Auto-generated method stub
737-
return null;
736+
req.method(Method.PUT);
737+
this.execute();
738+
return res.parse();
738739
}
739740

740741
public Document delete() throws IOException {
741-
// TODO Auto-generated method stub
742-
return null;
742+
req.method(Method.DELETE);
743+
this.execute();
744+
return res.parse();
745+
743746
}
744747

745-
public Document head() throws IOException {
746-
// TODO Auto-generated method stub
747-
return null;
748+
public Map<String, String> head() throws IOException {
749+
req.method(Method.HEAD);
750+
this.execute();
751+
752+
return res.headers();
748753
}
749754

750755

751756

757+
758+
752759

753760
}

src/test/java/com/monday/xsoup/helper/HttpConnectionTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,12 @@ public class HttpConnectionTest {
151151
assertEquals("1 messages are added to test",con.execute().body());
152152

153153
}
154+
155+
156+
@Test public void head() throws IOException
157+
{
158+
Connection con = HttpConnection.connect("http://httpsns.appspot.com/api?name=test");
159+
160+
System.out.println(con.head().get("Date"));
161+
}
154162
}

0 commit comments

Comments
 (0)