|
|
|
@ -61,11 +61,7 @@ public class HttpHeaderDelegate<TARGET extends ITarget, ENTITY extends AbsEntity |
|
|
|
|
ALog.w(TAG, "设置header失败,header对应的value不能为null"); |
|
|
|
|
return mTarget; |
|
|
|
|
} |
|
|
|
|
if (mTaskEntity.getHeaders().get(key) == null) { |
|
|
|
|
mTaskEntity.getHeaders().put(key, value); |
|
|
|
|
} else if (!mTaskEntity.getHeaders().get(key).equals(value)) { |
|
|
|
|
mTaskEntity.getHeaders().put(key, value); |
|
|
|
|
} |
|
|
|
|
addHeader(mTaskEntity, key, value); |
|
|
|
|
return mTarget; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -81,6 +77,35 @@ public class HttpHeaderDelegate<TARGET extends ITarget, ENTITY extends AbsEntity |
|
|
|
|
ALog.w(TAG, "设置header失败,map没有header数据"); |
|
|
|
|
return mTarget; |
|
|
|
|
} |
|
|
|
|
addHeaders(mTaskEntity, headers); |
|
|
|
|
return mTarget; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置请求类型,POST或GET,默认为在GET |
|
|
|
|
* 只试用于HTTP请求 |
|
|
|
|
* |
|
|
|
|
* @param requestEnum {@link RequestEnum} |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public TARGET setRequestMode(RequestEnum requestEnum) { |
|
|
|
|
setRequestMode(mTaskEntity, requestEnum); |
|
|
|
|
return mTarget; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void addHeader(AbsTaskEntity taskEntity, String key, String value) { |
|
|
|
|
if (taskEntity.getHeaders().get(key) == null) { |
|
|
|
|
taskEntity.getHeaders().put(key, value); |
|
|
|
|
} else if (!taskEntity.getHeaders().get(key).equals(value)) { |
|
|
|
|
taskEntity.getHeaders().put(key, value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setRequestMode(AbsTaskEntity taskEntity, RequestEnum requestEnum) { |
|
|
|
|
taskEntity.setRequestEnum(requestEnum); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void addHeaders(AbsTaskEntity taskEntity, Map<String, String> headers) { |
|
|
|
|
/* |
|
|
|
|
两个map比较逻辑 |
|
|
|
|
1、比对key是否相同 |
|
|
|
@ -88,9 +113,9 @@ public class HttpHeaderDelegate<TARGET extends ITarget, ENTITY extends AbsEntity |
|
|
|
|
3、只有当上面两个步骤中key 和 value都相同时才能任务两个map数据一致 |
|
|
|
|
*/ |
|
|
|
|
boolean mapEquals = false; |
|
|
|
|
if (mTaskEntity.getHeaders().size() == headers.size()) { |
|
|
|
|
if (taskEntity.getHeaders().size() == headers.size()) { |
|
|
|
|
int i = 0; |
|
|
|
|
Set<String> keys = mTaskEntity.getHeaders().keySet(); |
|
|
|
|
Set<String> keys = taskEntity.getHeaders().keySet(); |
|
|
|
|
for (String key : keys) { |
|
|
|
|
if (headers.containsKey(key)) { |
|
|
|
|
i++; |
|
|
|
@ -98,9 +123,9 @@ public class HttpHeaderDelegate<TARGET extends ITarget, ENTITY extends AbsEntity |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (i == mTaskEntity.getHeaders().size()) { |
|
|
|
|
if (i == taskEntity.getHeaders().size()) { |
|
|
|
|
int j = 0; |
|
|
|
|
Collection<String> values = mTaskEntity.getHeaders().values(); |
|
|
|
|
Collection<String> values = taskEntity.getHeaders().values(); |
|
|
|
|
for (String value : values) { |
|
|
|
|
if (headers.containsValue(value)) { |
|
|
|
|
j++; |
|
|
|
@ -108,32 +133,18 @@ public class HttpHeaderDelegate<TARGET extends ITarget, ENTITY extends AbsEntity |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (j == mTaskEntity.getHeaders().size()) { |
|
|
|
|
if (j == taskEntity.getHeaders().size()) { |
|
|
|
|
mapEquals = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mapEquals) { |
|
|
|
|
mTaskEntity.getHeaders().clear(); |
|
|
|
|
taskEntity.getHeaders().clear(); |
|
|
|
|
Set<String> keys = headers.keySet(); |
|
|
|
|
for (String key : keys) { |
|
|
|
|
mTaskEntity.getHeaders().put(key, headers.get(key)); |
|
|
|
|
} |
|
|
|
|
taskEntity.getHeaders().put(key, headers.get(key)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return mTarget; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置请求类型,POST或GET,默认为在GET |
|
|
|
|
* 只试用于HTTP请求 |
|
|
|
|
* |
|
|
|
|
* @param requestEnum {@link RequestEnum} |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public TARGET setRequestMode(RequestEnum requestEnum) { |
|
|
|
|
mTaskEntity.setRequestEnum(requestEnum); |
|
|
|
|
return mTarget; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|