Skip to content

Commit

Permalink
Merge pull request #827 from Hans-Wu-cn/master
Browse files Browse the repository at this point in the history
fix: It is suspected that the curl request generated under a single file cannot obtain the header correctly. Currently, the debug execution is successful under multiple files, and the curl command generated by copying cannot be requested. Changing to double quotation marks is normal
  • Loading branch information
shalousun authored Jun 25, 2024
2 parents f34466c + 790858e commit 263cbb5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/ly/doc/utils/CurlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ public static String toCurl(CurlRequest request) {
if (StringUtil.isNotEmpty(request.getContentType()) &&
!MediaType.APPLICATION_FORM_URLENCODED_VALUE.equals(request.getContentType())) {
sb.append(" -H");
sb.append(" 'Content-Type: ").append(request.getContentType()).append("'");
sb.append(" \"Content-Type: ").append(request.getContentType()).append("\"");
}
if (CollectionUtil.isNotEmpty(request.getReqHeaders())) {
for (ApiReqParam reqHeader : request.getReqHeaders()) {
sb.append(" -H");
if (StringUtil.isEmpty(reqHeader.getValue())) {
sb.append(" '").append(reqHeader.getName()).append("'");
sb.append(" \"").append(reqHeader.getName()).append("\"");
} else {
sb.append(" '").append(reqHeader.getName()).append(':')
.append(reqHeader.getValue()).append("'");
sb.append(" \"").append(reqHeader.getName()).append(':')
.append(reqHeader.getValue()).append("\"");
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/com/ly/doc/util/CurlUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.ly.doc.util;

import com.ly.doc.constants.ApiReqParamInTypeEnum;
import com.ly.doc.model.ApiReqParam;
import com.ly.doc.model.request.CurlRequest;
import com.ly.doc.utils.CurlUtil;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class CurlUtilTest {
/**
* test header name
*/
@Test
public void testHeaderName() {
ApiReqParam apiReqParam = ApiReqParam.builder()
.setName("Authorization")
.setValue("lbEfFvLigPuN2pDMxWaTviVuGwhg74T11geUiNcaYwZ4ZAZB780vkQo8OBMVpZmT")
.setParamIn(ApiReqParamInTypeEnum.HEADER.getValue());
CurlRequest builder = CurlRequest.builder();
builder.setUrl("http://127.0.0.1:8080/region/list")
.setType("POST")
.setContentType("application/json")
.setReqHeaders(Arrays.asList(apiReqParam));
String curl = CurlUtil.toCurl(builder);
System.out.println(curl);
}
}

0 comments on commit 263cbb5

Please sign in to comment.