@@ -71,15 +71,24 @@ static bool RESTERR(HTTPRequest* req, enum HTTPStatusCode status, string message
71
71
return false ;
72
72
}
73
73
74
- static enum RetFormat ParseDataFormat (vector< string>& params , const string& strReq)
74
+ static enum RetFormat ParseDataFormat (std:: string& param , const std:: string& strReq)
75
75
{
76
- boost::split (params, strReq, boost::is_any_of ( " . " ) );
77
- if (params. size () > 1 ) {
78
- for ( unsigned int i = 0 ; i < ARRAYLEN (rf_names); i++)
79
- if (params[ 1 ] == rf_names[i]. name )
80
- return rf_names[i ].rf ;
76
+ const std::string::size_type pos = strReq. rfind ( ' . ' );
77
+ if (pos == std::string::npos)
78
+ {
79
+ param = strReq;
80
+ return rf_names[0 ].rf ;
81
81
}
82
82
83
+ param = strReq.substr (0 , pos);
84
+ const std::string suff (strReq, pos + 1 );
85
+
86
+ for (unsigned int i = 0 ; i < ARRAYLEN (rf_names); i++)
87
+ if (suff == rf_names[i].name )
88
+ return rf_names[i].rf ;
89
+
90
+ /* If no suffix is found, return original string. */
91
+ param = strReq;
83
92
return rf_names[0 ].rf ;
84
93
}
85
94
@@ -121,10 +130,10 @@ static bool rest_headers(HTTPRequest* req,
121
130
{
122
131
if (!CheckWarmup (req))
123
132
return false ;
124
- vector< string> params ;
125
- const RetFormat rf = ParseDataFormat (params , strURIPart);
133
+ std:: string param ;
134
+ const RetFormat rf = ParseDataFormat (param , strURIPart);
126
135
vector<string> path;
127
- boost::split (path, params[ 0 ] , boost::is_any_of (" /" ));
136
+ boost::split (path, param , boost::is_any_of (" /" ));
128
137
129
138
if (path.size () != 2 )
130
139
return RESTERR (req, HTTP_BAD_REQUEST, " No header count specified. Use /rest/headers/<count>/<hash>.<ext>." );
@@ -196,10 +205,9 @@ static bool rest_block(HTTPRequest* req,
196
205
{
197
206
if (!CheckWarmup (req))
198
207
return false ;
199
- vector< string> params ;
200
- const RetFormat rf = ParseDataFormat (params , strURIPart);
208
+ std:: string hashStr ;
209
+ const RetFormat rf = ParseDataFormat (hashStr , strURIPart);
201
210
202
- string hashStr = params[0 ];
203
211
uint256 hash;
204
212
if (!ParseHashStr (hashStr, hash))
205
213
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hashStr);
@@ -268,8 +276,8 @@ static bool rest_chaininfo(HTTPRequest* req, const std::string& strURIPart)
268
276
{
269
277
if (!CheckWarmup (req))
270
278
return false ;
271
- vector< string> params ;
272
- const RetFormat rf = ParseDataFormat (params , strURIPart);
279
+ std:: string param ;
280
+ const RetFormat rf = ParseDataFormat (param , strURIPart);
273
281
274
282
switch (rf) {
275
283
case RF_JSON: {
@@ -293,8 +301,8 @@ static bool rest_mempool_info(HTTPRequest* req, const std::string& strURIPart)
293
301
{
294
302
if (!CheckWarmup (req))
295
303
return false ;
296
- vector< string> params ;
297
- const RetFormat rf = ParseDataFormat (params , strURIPart);
304
+ std:: string param ;
305
+ const RetFormat rf = ParseDataFormat (param , strURIPart);
298
306
299
307
switch (rf) {
300
308
case RF_JSON: {
@@ -318,8 +326,8 @@ static bool rest_mempool_contents(HTTPRequest* req, const std::string& strURIPar
318
326
{
319
327
if (!CheckWarmup (req))
320
328
return false ;
321
- vector< string> params ;
322
- const RetFormat rf = ParseDataFormat (params , strURIPart);
329
+ std:: string param ;
330
+ const RetFormat rf = ParseDataFormat (param , strURIPart);
323
331
324
332
switch (rf) {
325
333
case RF_JSON: {
@@ -343,10 +351,9 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
343
351
{
344
352
if (!CheckWarmup (req))
345
353
return false ;
346
- vector< string> params ;
347
- const RetFormat rf = ParseDataFormat (params , strURIPart);
354
+ std:: string hashStr ;
355
+ const RetFormat rf = ParseDataFormat (hashStr , strURIPart);
348
356
349
- string hashStr = params[0 ];
350
357
uint256 hash;
351
358
if (!ParseHashStr (hashStr, hash))
352
359
return RESTERR (req, HTTP_BAD_REQUEST, " Invalid hash: " + hashStr);
@@ -396,13 +403,13 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
396
403
{
397
404
if (!CheckWarmup (req))
398
405
return false ;
399
- vector< string> params ;
400
- enum RetFormat rf = ParseDataFormat (params , strURIPart);
406
+ std:: string param ;
407
+ const RetFormat rf = ParseDataFormat (param , strURIPart);
401
408
402
409
vector<string> uriParts;
403
- if (params. size () > 0 && params[ 0 ] .length () > 1 )
410
+ if (param .length () > 1 )
404
411
{
405
- std::string strUriParams = params[ 0 ] .substr (1 );
412
+ std::string strUriParams = param .substr (1 );
406
413
boost::split (uriParts, strUriParams, boost::is_any_of (" /" ));
407
414
}
408
415
0 commit comments