forked from cloudfoundry/docs-dev-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http2-protocol.html.md.erb
224 lines (159 loc) · 9.5 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
---
title: Routing HTTP/2 and gRPC traffic to apps
owner: CF for VMs Networking
---
Here are instructions for routing HTTP/2 and gRPC traffic to <%= vars.app_runtime_first %> apps.
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:
- 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 these 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
If your <%= vars.app_runtime_abbr %> deployment is configured to support HTTP/2,
then all traffic coming in to <%= vars.app_runtime_abbr %> supports HTTP/2.
The traffic is forwarded as HTTP/1.1 before it reaches your app unless configured otherwise.
<% if vars.platform_code != 'CF' %>
For more information, see [Configuring HTTP/2 support](https://docs.vmware.com/en/VMware-Tanzu-Application-Service/<%= vars.current_major_version %>/tas-for-vms/supporting-http2.html).
<% end %>
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.
If a client is familiar with the HTTP/2 specification,
your app receives HTTP/2 with prior knowledge.
For more information, see [Starting HTTP/2 with Prior Knowledge](https://datatracker.ietf.org/doc/html/rfc7540#section-3.4) in _RFC 7540: Hypertext Transfer Protocol Version 2 (HTTP/2)_.
## <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).
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:
- [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:
```console
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 important">
<span class="note__title"><strong>Important</strong></span>
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
The recommended way to do this is using the `routes` attribute in the manifest YAML file.
<p class="note important">
<span class="note__title"><strong>Important</strong></span>
The following procedure is supported only for cf CLI v6. The `--hostname` flag is deprecated in cf CLI v7, and must be specified in the manifest.</p>
To push an app that serves HTTP/2 traffic using the cf CLI (v6 only):
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 with the `--no-route` flag. Note that this flag is no longer unbinds all existing routes associated with the app.
```console
cf push --no-route
```
2. You can 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.
3. 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 activated 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).
1. Send a gRPC request to the app using `grpcurl` by running the following command. 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 this:
```
Response contents:
{
"body": "Hello"
}
```
## <a id="sample-apps"></a> Sample applications
Here are some sample HTTP/2 and gRPC applications from the community. You can
use them to experiment with HTTP/2 and provide code examples for different
languages and frameworks.
- [ASP.NET Core HTTP/2 App](https://github.com/Gerg/dotnet_http2)
- [Golang CATs gRPC App](https://github.com/grpc/grpc-go)
- [Golang CATs HTTP/2 App](https://github.com/cloudfoundry/cf-acceptance-tests/tree/main/assets/http2)
- [Golang HTTP/2 Tile App](https://github.com/Gerg/http2_tile_demo)
- [Golang SAP gRPC App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/go-grpc)
- [Golang SAP HTTP/2 App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/go-http2)
- [Java SAP gRPC App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/java-grpc)
- [Java SAP HTTP/2 App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/java-http2)
- [Node SAP gRPC App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/node-grpc)
- [Node SAP HTTP/2 App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/node-http2)
- [Python SAP gRPC App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/python-grpc)
- [Python SAP HTTP/2 App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/python-http2)
- [Ruby SAP gRPC App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/ruby-grpc)
- [Ruby SAP HTTP/2 App](https://github.com/SAP-samples/cf-routing-samples/tree/main/http2/ruby-http2)