@@ -3,7 +3,15 @@ use crate::error;
33use crate :: message:: { FromPubSubMessage , Message } ;
44use bytes:: buf:: BufExt as _;
55use hyper:: { Method , StatusCode } ;
6+ use lazy_static:: lazy_static;
67use serde_derive:: { Deserialize , Serialize } ;
8+ use std:: env;
9+
10+ lazy_static ! {
11+ static ref PUBSUB_HOST : String = env:: var( "PUBSUB_EMULATOR_HOST" )
12+ . map( |host| format!( "http://{}" , host) )
13+ . unwrap_or_else( |_| String :: from( "https://pubsub.googleapis.com" ) ) ;
14+ }
715
816#[ derive( Deserialize ) ]
917struct Response {
@@ -35,7 +43,7 @@ impl Subscription {
3543 . as_ref ( )
3644 . expect ( "Subscription was not created using a client" ) ;
3745
38- let uri: hyper:: Uri = format ! ( "https://pubsub.googleapis.com/ v1/{}:acknowledge" , self . name)
46+ let uri: hyper:: Uri = format ! ( "{}/ v1/{}:acknowledge" , * PUBSUB_HOST , self . name)
3947 . parse ( )
4048 . unwrap ( ) ;
4149
@@ -57,7 +65,7 @@ impl Subscription {
5765 . as_ref ( )
5866 . expect ( "Subscription was not created using a client" ) ;
5967
60- let uri: hyper:: Uri = format ! ( "https://pubsub.googleapis.com/ v1/{}:pull" , self . name)
68+ let uri: hyper:: Uri = format ! ( "{}/ v1/{}:pull" , * PUBSUB_HOST , self . name)
6169 . parse ( )
6270 . unwrap ( ) ;
6371
@@ -104,7 +112,7 @@ impl Subscription {
104112 . client
105113 . expect ( "Subscription was not created using a client" ) ;
106114
107- let uri: hyper:: Uri = format ! ( "https://pubsub.googleapis.com/ v1/{}" , self . name)
115+ let uri: hyper:: Uri = format ! ( "{}/ v1/{}" , * PUBSUB_HOST , self . name)
108116 . parse ( )
109117 . unwrap ( ) ;
110118
0 commit comments