Skip to content

Commit

Permalink
Merge pull request square#1674 from square/jwilson_0525_url_doc_bugs
Browse files Browse the repository at this point in the history
Better docs on new URL exceptions.
  • Loading branch information
JakeWharton committed May 25, 2015
2 parents bc2aad3 + 0ac2471 commit 8072cc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ _2015-05-22_

_2015-05-16_

* **New HttpUrl API.** It's like `java.net.URL` but good.
* **New HttpUrl API.** It's like `java.net.URL` but good. Note that
`Request.Builder.url()` now throws `IllegalArgumentException` on malformed
URLs. (Previous releases would throw a `MalformedURLException` when calling
a malformed URL.)

* **We've improved connect failure recovery.** We now differentiate between
setup, connecting, and connected and implement appropriate recovery rules
Expand Down
12 changes: 12 additions & 0 deletions okhttp/src/main/java/com/squareup/okhttp/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public Builder url(HttpUrl url) {
return this;
}

/**
* Sets the URL target of this request.
*
* @throws IllegalArgumentException if {@code url} is not a valid HTTP or HTTPS URL. Avoid this
* exception by calling {@link HttpUrl#parse}; it returns null for invalid URLs.
*/
public Builder url(String url) {
if (url == null) throw new IllegalArgumentException("url == null");

Expand All @@ -158,6 +164,12 @@ public Builder url(String url) {
return url(parsed);
}

/**
* Sets the URL target of this request.
*
* @throws IllegalArgumentException if the scheme of {@code url} is not {@code http} or {@code
* https}.
*/
public Builder url(URL url) {
if (url == null) throw new IllegalArgumentException("url == null");
HttpUrl parsed = HttpUrl.get(url);
Expand Down

0 comments on commit 8072cc8

Please sign in to comment.