Skip to content

Commit

Permalink
Merge pull request #497 from Celeter/master
Browse files Browse the repository at this point in the history
UA支持多个请求头
  • Loading branch information
gedoor committed May 1, 2020
2 parents f93042f + b4106c8 commit 90382f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/src/main/assets/updateLog.md
Expand Up @@ -3,6 +3,9 @@
* 弄了个企业公众号[开源阅读](),后面弄好后会把原来的[开源阅读软件]()迁移过来
* [3.0下载地址](https://www.coolapk.com/apk/256030)

**2020/05/01**
* UA用作header,支持Map

**2020/04/25**
* 修复jsonpath解析的bug

Expand Down
Expand Up @@ -2,17 +2,20 @@

import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.kunfei.bookshelf.DbHelper;
import com.kunfei.bookshelf.MApplication;
import com.kunfei.bookshelf.R;
import com.kunfei.bookshelf.bean.BookSourceBean;
import com.kunfei.bookshelf.bean.CookieBean;
import com.kunfei.bookshelf.utils.StringUtils;

import java.util.HashMap;
import java.util.Map;

import static android.text.TextUtils.isEmpty;
import static com.kunfei.bookshelf.constant.AppConstant.DEFAULT_USER_AGENT;
import static com.kunfei.bookshelf.constant.AppConstant.MAP_STRING;

/**
* Created by GKF on 2018/3/2.
Expand All @@ -24,16 +27,24 @@ public class AnalyzeHeaders {

public static Map<String, String> getMap(BookSourceBean bookSourceBean) {
Map<String, String> headerMap = new HashMap<>();
if (bookSourceBean != null && !isEmpty(bookSourceBean.getHttpUserAgent())) {
headerMap.put("User-Agent", bookSourceBean.getHttpUserAgent());
} else {
headerMap.put("User-Agent", getDefaultUserAgent());
}
if (bookSourceBean != null) {
String headers = bookSourceBean.getHttpUserAgent();
if (!isEmpty(headers)) {
if (StringUtils.isJsonObject(headers)) {
Map<String, String> map = new Gson().fromJson(headers, MAP_STRING);
headerMap.putAll(map);
} else {
headerMap.put("User-Agent", headers);
}
} else {
headerMap.put("User-Agent", getDefaultUserAgent());
}
CookieBean cookie = DbHelper.getDaoSession().getCookieBeanDao().load(bookSourceBean.getBookSourceUrl());
if (cookie != null) {
headerMap.put("Cookie", cookie.getCookie());
}
} else {
headerMap.put("User-Agent", getDefaultUserAgent());
}
return headerMap;
}
Expand Down

0 comments on commit 90382f3

Please sign in to comment.