@@ -70,50 +70,17 @@ exports.lazyGlobals = (req, res) => {
7070} ;
7171// [END functions_tips_lazy_globals]
7272
73- // [START functions_tips_ephemeral_agent]
74- // [START functions_tips_cached_agent]
73+ // [START functions_tips_connection_pooling]
7574const http = require ( 'http' ) ;
76- // [END functions_tips_ephemeral_agent]
7775const agent = new http . Agent ( { keepAlive : true } ) ;
78- // [END functions_tips_cached_agent]
7976
80- // [START functions_tips_ephemeral_agent]
81-
82- /**
83- * HTTP Cloud Function that uses an ephemeral HTTP agent
84- *
85- * @param {Object } req Cloud Function request context.
86- * @param {Object } res Cloud Function response context.
87- */
88- exports . ephemeralAgent = ( req , res ) => {
89- req = http . request ( {
90- host : '<HOST>' ,
91- port : 80 ,
92- path : '<PATH>' ,
93- method : 'GET'
94- } , resInner => {
95- let rawData = '' ;
96- resInner . setEncoding ( 'utf8' ) ;
97- resInner . on ( 'data' , chunk => { rawData += chunk ; } ) ;
98- resInner . on ( 'end' , ( ) => {
99- res . status ( 200 ) . send ( `Data: ${ rawData } ` ) ;
100- } ) ;
101- } ) ;
102- req . on ( 'error' , ( e ) => {
103- res . status ( 500 ) . send ( `Error: ${ e . message } ` ) ;
104- } ) ;
105- req . end ( ) ;
106- } ;
107- // [END functions_tips_ephemeral_agent]
108-
109- // [START functions_tips_cached_agent]
11077/**
111- * HTTP Cloud Function that uses a cached HTTP agent
78+ * HTTP Cloud Function that caches an HTTP agent to pool HTTP connections.
11279 *
11380 * @param {Object } req Cloud Function request context.
11481 * @param {Object } res Cloud Function response context.
11582 */
116- exports . cachedAgent = ( req , res ) => {
83+ exports . connectionPooling = ( req , res ) => {
11784 req = http . request ( {
11885 host : '' ,
11986 port : 80 ,
@@ -133,7 +100,7 @@ exports.cachedAgent = (req, res) => {
133100 } ) ;
134101 req . end ( ) ;
135102} ;
136- // [END functions_tips_cached_agent ]
103+ // [END functions_tips_connection_pooling ]
137104
138105// [START functions_tips_infinite_retries]
139106/**
0 commit comments