routable-android icon indicating copy to clipboard operation
routable-android copied to clipboard

URLEncodedUtils and NameValuePair shouldn't be here

Open ryanhoo opened this issue 8 years ago • 1 comments

There are only a few lines of code which use http-client's related APIs: URLEncodedUtils & NameValuePair.

List<NameValuePair> query = URLEncodedUtils.parse(parsedUri, "utf-8");

for (NameValuePair pair : query) {
    routerParams.openParams.put(pair.getName(), pair.getValue());
}

They shouldn't be here because:

  • It can be easily replaced
  • MultiDex 65k method count limits: http-client has 7521 methods in total. It doesn't seem to be a problem. But think of the limit is 65535, the cost is too much for a small router component.

They can be replaced by Uri. It handles urls such as xxx?key1=val+1&key2=val%202 pretty well.

Uri uri = Uri.parse(url);
Set<String> queryKeys = uri.getQueryParameterNames();
for (String key : queryKeys) {
    routerParams.openParams.put(key, uri.getQueryParameter(key));
}

Sure Uri.getQueryParameterNames() is only available since API 11 and if you want to support API 9, then you can also achive the goal by using Uri.getEncodedQuery(), it's available since API 1. Of course you need to parse the parameters set by your own, but that wouldn't be a problem.

This project uses http-client's API but there seems no jar file nor gradle dependence declared.

It's a nice project but I don't think anyone can run the testcases in this project without too much pain. I was going to make a pull request but I found this project doesn't practice gradle very well. I might need to refactor the whole structure if I want to start to work on this project, I guess.

A nice open source project should be friendly to other programmers, isn't it?

ryanhoo avatar Mar 25 '16 04:03 ryanhoo

it's a great idea when someone not uses the httpClient anymore...

tanweijiu avatar Mar 25 '16 06:03 tanweijiu