forked from cloudfoundry/docs-dev-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp2-protocol.html.md.erb
203 lines (138 loc) · 7.58 KB
/
http2-protocol.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
---
title: Routing HTTP/2 and gRPC Traffic to Apps
owner: CF for VMs Networking
---
<% current_page.data.title = "Routing HTTP/2 and gRPC Traffic to Apps" %>
This topic describes how to route HTTP/2 and gRPC traffic to <%= vars.app_runtime_first %> apps.
## <a id="overview"></a> Overview
HTTP/2 is the second major version of the the HTTP protocol.
<%= vars.http2_support_version %>
For more information about the HTTP/2 protocol, see [RFC 7540](https://datatracker.ietf.org/doc/html/rfc7540).
gRPC is a Remote Procedure Call (RPC) framework that uses HTTP/2 as its transport medium.
It is especially useful for managing communication between apps in a microservices cluster.
For apps to serve gRPC traffic, every network hop between the client and app must use HTTP/2.
For more information, see [gRPC](https://grpc.io/).
### <a id="performance"></a> Performance
HTTP/2 can provide performance improvements for apps that are built to do the following:
- Load many resources in parallel. For example, an HTML page that loads many images or JavaScript files.
- Use large and repetitive headers.
Other apps might see minimal or no performance increases.
Experiment with your app to see how serving HTTP/2 affects its performance.
For an example of an app that benefits from HTTP/2, see the [Cloud Foundry HTTP/2 Tile Demo App](https://github.com/Gerg/http2_tile_demo).
### <a id="limitations"></a> Limitations
HTTP/2 support in <%= vars.app_runtime_abbr %> has the following limitations:
- End-to-end HTTP/2 is not available for Windows Diego Cells. Routes with HTTP/2 mappings continue to send HTTP/1.1 traffic to apps that run on Windows Diego Cells.
- Routes that have route services bound to them might not support end-to-end HTTP/2 depending on what protocols the bound service supports. For more information, see [Route Services](../services/route-services.html).
## <a id="http2-with-cf"></a> How Pushing Apps with HTTP/2 Works
This section describes how pushing apps with HTTP/2 works.
If your <%= vars.app_runtime_abbr %> deployment is configured to support HTTP/2,
then all traffic ingressing to <%= vars.app_runtime_abbr %> supports HTTP/2.
The traffic is forwarded as HTTP/1.1 before it reaches your app unless configured otherwise.
<%= vars.http2_admin_link %>
To serve gRPC traffic, your app must use HTTP/2 for all network hops.
Configure your route to send HTTP/2 traffic to your app.
When configured, traffic that matches the route is always sent to your app over HTTP/2 regardless of the original ingress protocol.
For example, external HTTP/1.1 requests are forwarded to your app over HTTP/2.
Your app does not have the opportunity to negotiate what protocol it receives.
<p class="note"><strong>Note:</strong>
If a client is familiar with the HTTP/2 specification,
your app receives HTTP/2 with prior knowledge.
For more information, see <a href="https://datatracker.ietf.org/doc/html/rfc7540#section-3.4">Starting HTTP/2 with Prior Knowledge</a> in
<em>RFC 7540: Hypertext Transfer Protocol Version 2 (HTTP/2)</em>.</p>
## <a id="push-apps"></a> Push Apps with HTTP/2 Support
This section describes how to push <%= vars.app_runtime_abbr %> apps with support for HTTP/2.
You do not need to make changes to existing apps to support HTTP/2.
For information about pushing an HTTP/1.1 app that serves HTTP/2 traffic, see [Push an HTTP/1.1 App that Serves HTTP/2](#http1-app) below.
There are multiple ways to push an app with end-to-end HTTP/2.
You can push the app using either the app manifest or the Cloud Foundry Command Line Interface (cf CLI).
You can also use either method to push an app that serves gRPC traffic.
To push an app with end-to-end HTTP/2, see the following sections:
- [Push an App with End-to-End HTTP/2 Using the App Manifest](#e2e-manifest)
- [Push an App with End-to-End HTTP/2 Using the cf CLI](#e2e-cli)
- [Push a gRPC App](#grpc-app)
### <a id="http1-app"></a> Push an HTTP/1.1 App that Serves HTTP/2
To push an HTTP/1.1 app that can serve HTTP/2 traffic:
1. Push the HTTP/1.1 app by running:
```
cf push MY-APP
```
Where `MY-APP` is the name of your app.
1. Send an HTTP/2 request to the app by running:
```
curl MY-APP.EXAMPLE.COM --http2 -v
```
Where `MY-APP.EXAMPLE.COM` is the route mapped to your app.<br><br>
The request and response are both issued over HTTP/2.
<p class="note"><strong>Note:</strong> To issue this request, you must use a version of <code>curl</code> that supports HTTP/2.</p>
1. Review the app logs by running:
```
cf logs MY-APP
```
The request to the app is issued over HTTP/1.1.
### <a id="e2e-manifest"></a> Push an App with End-to-End HTTP/2 Using the App Manifest
To push an app that serves HTTP/2 traffic using the app manifest:
1. Use an app that supports serving HTTP/2 traffic with prior knowledge.
For example, you can use the HTTP/2 test app from [Cloud Foundry Acceptance Tests](https://github.com/cloudfoundry/cf-acceptance-tests/tree/main/assets/http2) on GitHub.
1. Create an app manifest named `manifest.yml` with a route mapped to the app with HTTP/2:
```yaml
---
applications:
- name: MY-APP
routes:
- route: MY-APP.EXAMPLE.COM
protocol: http2
```
Where `MY-APP` is the name of your app and `MY-APP.EXAMPLE.COM` is the route you want to map to your app.
1. Push the app with the manifest by running:
```
cf push -f manifest.yml
```
1. Send an HTTP/2 request to the app by running:
```
curl MY-APP.EXAMPLE.COM --http2 -v
```
The request and response are both sent over HTTP/2. The response from the test app includes the protocol.<br><br>For example:
```
Hello, /, TLS: false, Protocol: HTTP/2.0
```
The response shows that the request was received over HTTP/2.
### <a id="e2e-cli"></a> Push an App with End-to-End HTTP/2 Using the cf CLI
To push an app that serves HTTP/2 traffic using the cf CLI:
1. Use an app that supports serving HTTP/2 traffic with prior knowledge.
For example, you can use the HTTP/2 test app from [Cloud Foundry Acceptance Tests](https://github.com/cloudfoundry/cf-acceptance-tests/tree/main/assets/http2) on GitHub.
1. Push the app without a default route by running:
```
cf push --no-route
```
1. Map a route with destination protocol `http2` by running:
```
cf map-route MY-APP EXAMPLE.COM --hostname host --destination-protocol http2
```
Where `MY-APP` is the name of your app and `EXAMPLE.COM` is the route you want to map to your app.
1. Send an HTTP/2 request to the app by running:
```
curl HOST.EXAMPLE.COM --http2 -v
```
The request and response are both sent over HTTP/2. The response from the test app includes the protocol.<br><br>For example:
```
Hello, /, TLS: false, Protocol: HTTP/2.0
```
The response shows that the request was received over HTTP/2.
### <a id="grpc-app"></a> Push a gRPC App
To push an app that serves gRPC traffic:
1. Use an app that supports serving gRPC traffic.
For example, you can use the gRPC test app from [Cloud Foundry Acceptance Tests](https://github.com/cloudfoundry/cf-acceptance-tests/tree/main/assets/grpc) on GitHub.
1. Push the app with HTTP/2 enabled using either the app manifest or the cf CLI.
See [Push an App with End-to-End HTTP/2 Using the App Manifest](#e2e-manifest) or [Push an App with End-to-End HTTP/2 Using the cf CLI](#e2e-cli) above.
1. Send a gRPC request to the app using `grpcurl` by running the command below. For more information, see [grpcurl](https://github.com/fullstorydev/grpcurl).
```
grpcurl -vv -import-path ./test/ -proto test.proto MY-APP.EXAMPLE.COM:443 test.Test.Run
```
Where `MY-APP.EXAMPLE.COM` is the route to your app.<br><br>
A successful response looks like the following:
```
Response contents:
{
"body": "Hello"
}
```