Skip to content

Commit

Permalink
修正 HttpData 中 responseHeaders 字段类型
Browse files Browse the repository at this point in the history
  • Loading branch information
getActivity committed Mar 11, 2024
1 parent 9c6d71a commit d49f3c5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dependencies {
implementation 'com.github.getActivity:Toaster:12.6'

// 权限请求框架:https://github.com/getActivity/XXPermissions
implementation 'com.github.getActivity:XXPermissions:18.5'
implementation 'com.github.getActivity:XXPermissions:18.6'

// 标题栏框架:https://github.com/getActivity/TitleBar
implementation 'com.github.getActivity:TitleBar:10.5'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.hjq.easy.demo.http.api;

import androidx.annotation.NonNull;

import com.hjq.http.annotation.HttpRename;
import com.hjq.http.config.IRequestApi;

import java.util.List;

/**
Expand All @@ -30,7 +28,7 @@ public SearchBlogsApi setKeyword(String keyword) {
return this;
}

public final static class Bean {
public static final class Bean {

private int curPage;
private int offset;
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/hjq/easy/demo/http/model/HttpData.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.hjq.easy.demo.http.model;

import androidx.annotation.Nullable;

import okhttp3.Headers;
import java.util.Map;

/**
* author : Android 轮子哥
Expand All @@ -14,7 +13,7 @@ public class HttpData<T> {

/** 响应头 */
@Nullable
private Headers responseHeaders;
private Map<String, String> responseHeaders;

/** 返回码 */
private int errorCode;
Expand All @@ -24,12 +23,12 @@ public class HttpData<T> {
@Nullable
private T data;

public void setResponseHeaders(@Nullable Headers responseHeaders) {
public void setResponseHeaders(@Nullable Map<String, String> responseHeaders) {
this.responseHeaders = responseHeaders;
}

@Nullable
public Headers getResponseHeaders() {
public Map<String, String> getResponseHeaders() {
return responseHeaders;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.lang.reflect.Type;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Headers;
import okhttp3.Response;
import okhttp3.ResponseBody;
Expand Down Expand Up @@ -116,7 +118,14 @@ public Object requestSuccess(@NonNull HttpRequest<?> httpRequest, @NonNull Respo

if (result instanceof HttpData) {
HttpData<?> model = (HttpData<?>) result;
model.setResponseHeaders(response.headers());
Headers headers = response.headers();
int headersSize = headers.size();
Map<String, String> headersMap = new HashMap<>(headersSize);
for (int i = 0; i < headersSize; i++) {
headersMap.put(headers.name(i), headers.value(i));
}
// Github issue 地址:https://github.com/getActivity/EasyHttp/issues/233
model.setResponseHeaders(headersMap);

if (model.isRequestSuccess()) {
// 代表执行成功
Expand Down

0 comments on commit d49f3c5

Please sign in to comment.