@@ -138,18 +138,48 @@ func (p *HTTPPool) PickPeer(key string) (ProtoGetter, bool) {
138138	return  nil , false 
139139}
140140
141- func  (p  * HTTPPool ) ServeHTTP (w  http.ResponseWriter , r  * http.Request ) {
142- 	// Parse request. 
141+ func  (p  * HTTPPool ) parseRequest (r  * http.Request ) (groupName , key  string , ok  bool ) {
143142	if  ! strings .HasPrefix (r .URL .Path , p .opts .BasePath ) {
144143		panic ("HTTPPool serving unexpected path: "  +  r .URL .Path )
145144	}
146145	parts  :=  strings .SplitN (r .URL .Path [len (p .opts .BasePath ):], "/" , 2 )
147146	if  len (parts ) !=  2  {
147+ 		return 
148+ 	}
149+ 	groupName  =  parts [0 ]
150+ 	key  =  parts [1 ]
151+ 
152+ 	queries , err  :=  url .ParseQuery (r .URL .RawQuery )
153+ 	if  err  !=  nil  {
154+ 		// Still accept groupName and key in path. 
155+ 		ok  =  true 
156+ 		return 
157+ 	}
158+ 
159+ 	var  uerr  error 
160+ 	if  queries .Get ("escaped" ) ==  "true"  {
161+ 		groupName , uerr  =  url .QueryUnescape (groupName )
162+ 		if  uerr  !=  nil  {
163+ 			ok  =  false 
164+ 			return 
165+ 		}
166+ 		key , uerr  =  url .QueryUnescape (key )
167+ 		if  uerr  !=  nil  {
168+ 			ok  =  false 
169+ 			return 
170+ 		}
171+ 	}
172+ 
173+ 	ok  =  true 
174+ 	return 
175+ }
176+ 
177+ func  (p  * HTTPPool ) ServeHTTP (w  http.ResponseWriter , r  * http.Request ) {
178+ 	groupName , key , ok  :=  p .parseRequest (r )
179+ 	if  ! ok  {
148180		http .Error (w , "bad request" , http .StatusBadRequest )
149181		return 
150182	}
151- 	groupName  :=  parts [0 ]
152- 	key  :=  parts [1 ]
153183
154184	// Fetch the value for this group/key. 
155185	group  :=  GetGroup (groupName )
@@ -191,7 +221,7 @@ var bufferPool = sync.Pool{
191221
192222func  (h  * httpGetter ) Get (context  Context , in  * pb.GetRequest , out  * pb.GetResponse ) error  {
193223	u  :=  fmt .Sprintf (
194- 		"%v%v/%v" ,
224+ 		"%v%v/%v?escaped=true " ,
195225		h .baseURL ,
196226		url .QueryEscape (in .GetGroup ()),
197227		url .QueryEscape (in .GetKey ()),
0 commit comments