mirror of
https://github.com/square/okhttp.git
synced 2025-07-31 05:04:26 +03:00
Move the API docs from /okhttp/api to /okhttp/4.x
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,7 +27,7 @@ obj
|
||||
.DS_Store
|
||||
|
||||
# Special Mkdocs files
|
||||
docs/api
|
||||
docs/4.x
|
||||
docs/changelog.md
|
||||
docs/contributing.md
|
||||
docs/index.md
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
The HTTP client’s job is to accept your request and produce its response. This is simple in theory but it gets tricky in practice.
|
||||
|
||||
## [Requests](http://square.github.io/okhttp/api/okhttp/okhttp3/-request/)
|
||||
## [Requests](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-request/)
|
||||
|
||||
Each HTTP request contains a URL, a method (like `GET` or `POST`), and a list of headers. Requests may also contain a body: a data stream of a specific content type.
|
||||
|
||||
## [Responses](http://square.github.io/okhttp/api/okhttp/okhttp3/-response/)
|
||||
## [Responses](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-response/)
|
||||
|
||||
The response answers the request with a code (like 200 for success or 404 for not found), headers, and its own optional body.
|
||||
|
||||
@ -28,20 +28,20 @@ If a conditional GET was successful, responses from the network and cache are me
|
||||
|
||||
When your requested URL has moved, the webserver will return a response code like `302` to indicate the document’s new URL. OkHttp will follow the redirect to retrieve a final response.
|
||||
|
||||
If the response issues an authorization challenge, OkHttp will ask the [`Authenticator`](http://square.github.io/okhttp/api/okhttp/okhttp3/-authenticator/) (if one is configured) to satisfy the challenge. If the authenticator supplies a credential, the request is retried with that credential included.
|
||||
If the response issues an authorization challenge, OkHttp will ask the [`Authenticator`](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-authenticator/) (if one is configured) to satisfy the challenge. If the authenticator supplies a credential, the request is retried with that credential included.
|
||||
|
||||
## Retrying Requests
|
||||
|
||||
Sometimes connections fail: either a pooled connection was stale and disconnected, or the webserver itself couldn’t be reached. OkHttp will retry the request with a different route if one is available.
|
||||
|
||||
## [Calls](http://square.github.io/okhttp/api/okhttp/okhttp3/-call/)
|
||||
## [Calls](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-call/)
|
||||
|
||||
With rewrites, redirects, follow-ups and retries, your simple request may yield many requests and responses. OkHttp uses `Call` to model the task of satisfying your request through however many intermediate requests and responses are necessary. Typically this isn’t many! But it’s comforting to know that your code will continue to work if your URLs are redirected or if you failover to an alternate IP address.
|
||||
|
||||
Calls are executed in one of two ways:
|
||||
|
||||
* **Synchronous:** your thread blocks until the response is readable.
|
||||
* **Asynchronous:** you enqueue the request on any thread, and get [called back](http://square.github.io/okhttp/api/okhttp/okhttp3/-callback/) on another thread when the response is readable.
|
||||
* **Asynchronous:** you enqueue the request on any thread, and get [called back](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-callback/) on another thread when the response is readable.
|
||||
|
||||
Calls can be canceled from any thread. This will fail the call if it hasn’t yet completed! Code that is writing the request body or reading the response body will suffer an `IOException` when its call is canceled.
|
||||
|
||||
@ -49,4 +49,4 @@ Calls can be canceled from any thread. This will fail the call if it hasn’t ye
|
||||
|
||||
For synchronous calls, you bring your own thread and are responsible for managing how many simultaneous requests you make. Too many simultaneous connections wastes resources; too few harms latency.
|
||||
|
||||
For asynchronous calls, [`Dispatcher`](http://square.github.io/okhttp/api/okhttp/okhttp3/-dispatcher/) implements policy for maximum simultaneous requests. You can set maximums per-webserver (default is 5), and overall (default is 64).
|
||||
For asynchronous calls, [`Dispatcher`](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-dispatcher/) implements policy for maximum simultaneous requests. You can set maximums per-webserver (default is 5), and overall (default is 64).
|
||||
|
@ -3,7 +3,7 @@ Connections
|
||||
|
||||
Although you provide only the URL, OkHttp plans its connection to your webserver using three types: URL, Address, and Route.
|
||||
|
||||
#### [URLs](http://square.github.io/okhttp/api/okhttp/okhttp3/-http-url/)
|
||||
#### [URLs](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-http-url/)
|
||||
|
||||
URLs (like `https://github.com/square/okhttp`) are fundamental to HTTP and the Internet. In addition to being a universal, decentralized naming scheme for everything on the web, they also specify how to access web resources.
|
||||
|
||||
@ -14,21 +14,21 @@ URLs are abstract:
|
||||
|
||||
They're also concrete: each URL identifies a specific path (like `/square/okhttp`) and query (like `?q=sharks&lang=en`). Each webserver hosts many URLs.
|
||||
|
||||
#### [Addresses](http://square.github.io/okhttp/api/okhttp/okhttp3/-address/)
|
||||
#### [Addresses](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-address/)
|
||||
|
||||
Addresses specify a webserver (like `github.com`) and all of the **static** configuration necessary to connect to that server: the port number, HTTPS settings, and preferred network protocols (like HTTP/2 or SPDY).
|
||||
|
||||
URLs that share the same address may also share the same underlying TCP socket connection. Sharing a connection has substantial performance benefits: lower latency, higher throughput (due to [TCP slow start](http://www.igvita.com/2011/10/20/faster-web-vs-tcp-slow-start/)) and conserved battery. OkHttp uses a [ConnectionPool](http://square.github.io/okhttp/api/okhttp/okhttp3/-connection-pool/) that automatically reuses HTTP/1.x connections and multiplexes HTTP/2 and SPDY connections.
|
||||
URLs that share the same address may also share the same underlying TCP socket connection. Sharing a connection has substantial performance benefits: lower latency, higher throughput (due to [TCP slow start](http://www.igvita.com/2011/10/20/faster-web-vs-tcp-slow-start/)) and conserved battery. OkHttp uses a [ConnectionPool](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-connection-pool/) that automatically reuses HTTP/1.x connections and multiplexes HTTP/2 and SPDY connections.
|
||||
|
||||
In OkHttp some fields of the address come from the URL (scheme, hostname, port) and the rest come from the [OkHttpClient](http://square.github.io/okhttp/api/okhttp/okhttp3/-ok-http-client/).
|
||||
In OkHttp some fields of the address come from the URL (scheme, hostname, port) and the rest come from the [OkHttpClient](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/).
|
||||
|
||||
#### [Routes](http://square.github.io/okhttp/api/okhttp/okhttp3/-route/)
|
||||
#### [Routes](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-route/)
|
||||
|
||||
Routes supply the **dynamic** information necessary to actually connect to a webserver. This is the specific IP address to attempt (as discovered by a DNS query), the exact proxy server to use (if a [ProxySelector](http://developer.android.com/reference/java/net/ProxySelector.html) is in use), and which version of TLS to negotiate (for HTTPS connections).
|
||||
|
||||
There may be many routes for a single address. For example, a webserver that is hosted in multiple datacenters may yield multiple IP addresses in its DNS response.
|
||||
|
||||
#### [Connections](http://square.github.io/okhttp/api/okhttp/okhttp3/-connection/)
|
||||
#### [Connections](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-connection/)
|
||||
|
||||
When you request a URL with OkHttp, here's what it does:
|
||||
|
||||
|
@ -6,9 +6,9 @@ OkHttp attempts to balance two competing concerns:
|
||||
* **Connectivity** to as many hosts as possible. That includes advanced hosts that run the latest versions of [boringssl](https://boringssl.googlesource.com/boringssl/) and less out of date hosts running older versions of [OpenSSL](https://www.openssl.org/).
|
||||
* **Security** of the connection. This includes verification of the remote webserver with certificates and the privacy of data exchanged with strong ciphers.
|
||||
|
||||
When negotiating a connection to an HTTPS server, OkHttp needs to know which [TLS versions](http://square.github.io/okhttp/api/okhttp/okhttp3/-tls-version/) and [cipher suites](http://square.github.io/okhttp/api/okhttp/okhttp3/-cipher-suite/) to offer. A client that wants to maximize connectivity would include obsolete TLS versions and weak-by-design cipher suites. A strict client that wants to maximize security would be limited to only the latest TLS version and strongest cipher suites.
|
||||
When negotiating a connection to an HTTPS server, OkHttp needs to know which [TLS versions](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-tls-version/) and [cipher suites](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-cipher-suite/) to offer. A client that wants to maximize connectivity would include obsolete TLS versions and weak-by-design cipher suites. A strict client that wants to maximize security would be limited to only the latest TLS version and strongest cipher suites.
|
||||
|
||||
Specific security vs. connectivity decisions are implemented by [ConnectionSpec](http://square.github.io/okhttp/api/okhttp/okhttp3/-connection-spec/). OkHttp includes four built-in connection specs:
|
||||
Specific security vs. connectivity decisions are implemented by [ConnectionSpec](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-connection-spec/). OkHttp includes four built-in connection specs:
|
||||
|
||||
* `RESTRICTED_TLS` is a secure configuration, intended to meet stricter compliance requirements.
|
||||
* `MODERN_TLS` is a secure configuration that connects to modern HTTPS servers.
|
||||
@ -47,7 +47,7 @@ OkHttpClient client = new OkHttpClient.Builder()
|
||||
|
||||
By default, OkHttp trusts the certificate authorities of the host platform. This strategy maximizes connectivity, but it is subject to certificate authority attacks such as the [2011 DigiNotar attack](http://www.computerworld.com/article/2510951/cybercrime-hacking/hackers-spied-on-300-000-iranians-using-fake-google-certificate.html). It also assumes your HTTPS servers’ certificates are signed by a certificate authority.
|
||||
|
||||
Use [CertificatePinner](http://square.github.io/okhttp/api/okhttp/okhttp3/-certificate-pinner/) to restrict which certificates and certificate authorities are trusted. Certificate pinning increases security, but limits your server team’s abilities to update their TLS certificates. **Do not use certificate pinning without the blessing of your server’s TLS administrator!**
|
||||
Use [CertificatePinner](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-certificate-pinner/) to restrict which certificates and certificate authorities are trusted. Certificate pinning increases security, but limits your server team’s abilities to update their TLS certificates. **Do not use certificate pinning without the blessing of your server’s TLS administrator!**
|
||||
|
||||
```java
|
||||
public CertificatePinning() {
|
||||
|
@ -343,7 +343,7 @@ Response caching uses HTTP headers for all configuration. You can add request he
|
||||
System.out.println("Response 2 equals Response 1? " + response1Body.equals(response2Body));
|
||||
}
|
||||
```
|
||||
To prevent a response from using the cache, use [`CacheControl.FORCE_NETWORK`](http://square.github.io/okhttp/api/okhttp/okhttp3/-cache-control/-f-o-r-c-e_-n-e-t-w-o-r-k/). To prevent it from using the network, use [`CacheControl.FORCE_CACHE`](http://square.github.io/okhttp/api/okhttp/okhttp3/-cache-control/-f-o-r-c-e_-c-a-c-h-e/). Be warned: if you use `FORCE_CACHE` and the response requires the network, OkHttp will return a `504 Unsatisfiable Request` response.
|
||||
To prevent a response from using the cache, use [`CacheControl.FORCE_NETWORK`](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-cache-control/-f-o-r-c-e_-n-e-t-w-o-r-k/). To prevent it from using the network, use [`CacheControl.FORCE_CACHE`](http://square.github.io/okhttp/4.x/okhttp/okhttp3/-cache-control/-f-o-r-c-e_-c-a-c-h-e/). Be warned: if you use `FORCE_CACHE` and the response requires the network, OkHttp will return a `504 Unsatisfiable Request` response.
|
||||
|
||||
#### [Canceling a Call](https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/CancelCall.java)
|
||||
|
||||
|
14
mkdocs.yml
14
mkdocs.yml
@ -45,13 +45,13 @@ nav:
|
||||
- 'Works with OkHttp': works_with_okhttp.md
|
||||
- 'Stack Overflow ⏏': https://stackoverflow.com/questions/tagged/okhttp?sort=active
|
||||
- '4.x API':
|
||||
- 'okhttp': api/okhttp/okhttp3/index.md
|
||||
- 'dnsoverhttps': api/okhttp-dnsoverhttps/okhttp3.dnsoverhttps/index.md
|
||||
- 'logging-interceptor': api/okhttp-logging-interceptor/okhttp3.logging/index.md
|
||||
- 'sse': api/okhttp-sse/okhttp3.sse/index.md
|
||||
- 'tls': api/okhttp-tls/okhttp3.tls/index.md
|
||||
- 'urlconnection': api/okhttp-urlconnection/okhttp3/index.md
|
||||
- 'mockwebserver': api/mockwebserver/okhttp3.mockwebserver/index.md
|
||||
- 'okhttp': 4.x/okhttp/okhttp3/index.md
|
||||
- 'dnsoverhttps': 4.x/okhttp-dnsoverhttps/okhttp3.dnsoverhttps/index.md
|
||||
- 'logging-interceptor': 4.x/okhttp-logging-interceptor/okhttp3.logging/index.md
|
||||
- 'sse': 4.x/okhttp-sse/okhttp3.sse/index.md
|
||||
- 'tls': 4.x/okhttp-tls/okhttp3.tls/index.md
|
||||
- 'urlconnection': 4.x/okhttp-urlconnection/okhttp3/index.md
|
||||
- 'mockwebserver': 4.x/mockwebserver/okhttp3.mockwebserver/index.md
|
||||
- '3.x API':
|
||||
- 'okhttp ⏏': https://square.github.io/okhttp/3.x/okhttp/
|
||||
- 'dnsoverhttps ⏏': https://square.github.io/okhttp/3.x/okhttp-dnsoverhttps/
|
||||
|
@ -18,7 +18,7 @@ dependencies {
|
||||
|
||||
afterEvaluate { project ->
|
||||
project.tasks.dokka {
|
||||
outputDirectory = "$rootDir/docs/api"
|
||||
outputDirectory = "$rootDir/docs/4.x"
|
||||
outputFormat = 'gfm'
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ dependencies {
|
||||
|
||||
afterEvaluate { project ->
|
||||
project.tasks.dokka {
|
||||
outputDirectory = "$rootDir/docs/api"
|
||||
outputDirectory = "$rootDir/docs/4.x"
|
||||
outputFormat = 'gfm'
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ dependencies {
|
||||
|
||||
afterEvaluate { project ->
|
||||
project.tasks.dokka {
|
||||
outputDirectory = "$rootDir/docs/api"
|
||||
outputDirectory = "$rootDir/docs/4.x"
|
||||
outputFormat = 'gfm'
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ dependencies {
|
||||
|
||||
afterEvaluate { project ->
|
||||
project.tasks.dokka {
|
||||
outputDirectory = "$rootDir/docs/api"
|
||||
outputDirectory = "$rootDir/docs/4.x"
|
||||
outputFormat = 'gfm'
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ Download
|
||||
implementation("com.squareup.okhttp3:okhttp-tls:3.14.2")
|
||||
```
|
||||
|
||||
[held_certificate]: http://square.github.io/okhttp/api/okhttp-tls/okhttp3.tls/-held-certificate/
|
||||
[held_certificate_builder]: http://square.github.io/okhttp/api/okhttp-tls/okhttp3.tls/-held-certificate/-builder/
|
||||
[handshake_certificates]: http://square.github.io/okhttp/api/okhttp-tls/okhttp3.tls/-handshake-certificates/
|
||||
[handshake_certificates_builder]: http://square.github.io/okhttp/api/okhttp-tls/okhttp3.tls/-handshake-certificates/-builder/
|
||||
[held_certificate]: http://square.github.io/okhttp/4.x/okhttp-tls/okhttp3.tls/-held-certificate/
|
||||
[held_certificate_builder]: http://square.github.io/okhttp/4.x/okhttp-tls/okhttp3.tls/-held-certificate/-builder/
|
||||
[handshake_certificates]: http://square.github.io/okhttp/4.x/okhttp-tls/okhttp3.tls/-handshake-certificates/
|
||||
[handshake_certificates_builder]: http://square.github.io/okhttp/4.x/okhttp-tls/okhttp3.tls/-handshake-certificates/-builder/
|
||||
|
@ -20,7 +20,7 @@ dependencies {
|
||||
|
||||
afterEvaluate { project ->
|
||||
project.tasks.dokka {
|
||||
outputDirectory = "$rootDir/docs/api"
|
||||
outputDirectory = "$rootDir/docs/4.x"
|
||||
outputFormat = 'gfm'
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ dependencies {
|
||||
|
||||
afterEvaluate { project ->
|
||||
project.tasks.dokka {
|
||||
outputDirectory = "$rootDir/docs/api"
|
||||
outputDirectory = "$rootDir/docs/4.x"
|
||||
outputFormat = 'gfm'
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ dependencies {
|
||||
|
||||
afterEvaluate { project ->
|
||||
project.tasks.dokka {
|
||||
outputDirectory = "$rootDir/docs/api"
|
||||
outputDirectory = "$rootDir/docs/4.x"
|
||||
outputFormat = 'gfm'
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user