Skip to content

Commit

Permalink
fix: repair upload yapi failed
Browse files Browse the repository at this point in the history
  • Loading branch information
lkqm committed Dec 6, 2023
1 parent 86ddb44 commit 8ec2900
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/apidocx/base/sdk/apifox/InternalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static String getUrlPath(String url) {
* 解析SetCookie为Cookie
*/
public static String parseCookie(Collection<String> setCookies) {
if (setCookies == null || setCookies.isEmpty()) {
return null;
}
return setCookies.stream()
.map(c -> {
List<HttpCookie> httpCookies = HttpCookie.parse(c);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/apidocx/base/sdk/eolink/InternalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static String getUrlPath(String url) {
* 解析SetCookie为Cookie
*/
public static String parseCookie(Collection<String> setCookies) {
if (setCookies == null || setCookies.isEmpty()) {
return null;
}
return setCookies.stream()
.map(c -> {
List<HttpCookie> httpCookies = HttpCookie.parse(c);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/apidocx/base/sdk/rap2/InternalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static String getUrlPath(String url) {
* 解析SetCookie为Cookie
*/
public static String parseCookie(Collection<String> setCookies) {
if (setCookies == null || setCookies.isEmpty()) {
return null;
}
return setCookies.stream()
.map(c -> {
List<HttpCookie> httpCookies = HttpCookie.parse(c);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/apidocx/base/sdk/rap2/Rap2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private Rap2Api createApiClient(String url) {
// 请求设置鉴权信息
boolean needCookie = !Rap2Constants.isLoginPath(template.path()) && !Rap2Constants.isCaptchaPath(template.path());
if (needCookie) {
template.header("cookie", getOrRefreshAccessToken(false));
template.header("Cookie", getOrRefreshAccessToken(false));
}
})
.responseInterceptor(ctx -> {
Expand All @@ -247,7 +247,7 @@ private Rap2Api createApiClient(String url) {
if (!loginResult.isSuccess()) {
throw new Rap2Exception(path, loginResult.getErrMsg());
}
Collection<String> setCookies = ctx.response().headers().get("set-cookie");
Collection<String> setCookies = ctx.response().headers().get("Set-Cookie");
this.cookies = InternalUtils.parseCookie(setCookies);
}
return value;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/apidocx/base/sdk/showdoc/InternalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static String getUrlPath(String url) {
* 解析SetCookie为Cookie
*/
public static String parseCookie(Collection<String> setCookies) {
if (setCookies == null || setCookies.isEmpty()) {
return null;
}
return setCookies.stream()
.map(c -> {
List<HttpCookie> httpCookies = HttpCookie.parse(c);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/apidocx/base/sdk/showdoc/ShowdocClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private URI uri(String path) {
public CaptchaResponse getCaptcha() {
try (feign.Response response = showdocApi.getCaptcha(uri(ShowdocConstants.GetCaptcha));) {
byte[] bytes = IOUtils.toByteArray(response.body().asInputStream());
this.captchaCookies = InternalUtils.parseCookie(response.headers().get("set-cookie"));
this.captchaCookies = InternalUtils.parseCookie(response.headers().get("Set-Cookie"));
CaptchaResponse captchaResponse = new CaptchaResponse();
captchaResponse.setBytes(bytes);
captchaResponse.setSession(this.captchaCookies);
Expand Down Expand Up @@ -171,7 +171,7 @@ private ShowdocApi createApiClient(String url) {
// 请求设置鉴权信息
boolean needCookie = !ShowdocConstants.isLoginPath(template.url()) && !ShowdocConstants.isCaptchaPath(template.url());
if (needCookie) {
template.header("cookie", getOrRefreshAccessToken(false));
template.header("Cookie", getOrRefreshAccessToken(false));
}
})
.responseInterceptor(ctx -> {
Expand All @@ -187,7 +187,7 @@ private ShowdocApi createApiClient(String url) {
}
// 登录存储cookie
if (ShowdocConstants.isLoginPath(requestUrl)) {
Collection<String> setCookies = ctx.response().headers().get("set-cookie");
Collection<String> setCookies = ctx.response().headers().get("Set-Cookie");
this.cookies = InternalUtils.parseCookie(setCookies);
}
return value;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/apidocx/base/sdk/yapi/InternalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public static String getUrlPath(String url) {
* 解析SetCookie为Cookie
*/
public static String parseCookie(Collection<String> setCookies) {
if (setCookies == null || setCookies.isEmpty()) {
return null;
}

return setCookies.stream()
.map(c -> {
List<HttpCookie> httpCookies = HttpCookie.parse(c);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/apidocx/base/sdk/yapi/YapiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ private YapiApi createYapiApi(String url) {
if (StringUtils.isNotEmpty(this.token)) {
template.query("token", this.token);
} else {
template.header("cookie", getOrRefreshAccessToken(false));
template.header("Cookie", getOrRefreshAccessToken(false));
}
}
})
.responseInterceptor(ctx -> {
// 登录存储cookie
String path = InternalUtils.getUrlPath(ctx.response().request().url());
if (YapiConstants.isLoginPath(path)) {
Collection<String> setCookies = ctx.response().headers().get("set-cookie");
Collection<String> setCookies = ctx.response().headers().get("Set-Cookie");
this.cookies = InternalUtils.parseCookie(setCookies);
}
// 响应异常转换
Expand Down

0 comments on commit 8ec2900

Please sign in to comment.