Skip to content

Commit

Permalink
Merge pull request #17 from sentrysoftware/feature/issue-15-manage-ur…
Browse files Browse the repository at this point in the history
…l-and-path-in-the-http-criterion-parser

Issue #15: Manage url and path in the HTTP Criterion parser
  • Loading branch information
NassimBtk authored Feb 8, 2024
2 parents d8e3c66 + 4a2c2b0 commit 16630ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,31 @@ public void visit(HttpCriterion httpCriterion) {
sink.text(" below to the managed host succeeds:");
sink.list();
sink.listItem();
// Retrieve URL and Path Fields values
String urlField = httpCriterion.getUrl();
String pathField = httpCriterion.getPath();
// Initialize the final URL value
String url = "";
// If both URL and Path fields aren't null, concatenate them
if (urlField != null && pathField != null) {
String.format(
"%s%s%s",
urlField,
urlField.endsWith("/") || pathField.startsWith("/") ? "" : "/",
urlField.endsWith("/") && pathField.startsWith("/") ? pathField.substring(1) : pathField
);
// if Only URL field value is found, use it
} else if (urlField != null) {
url = urlField;
// if Only Path field value is found, use it
} else if (pathField != null) {
url = pathField;
}
sink.rawText(
String.format(
"<b>%s</b> <code>%s</code>",
httpCriterion.getMethodOrDefault("GET"),
SinkHelper.replaceWithHtmlCode(httpCriterion.getUrl())
SinkHelper.replaceWithHtmlCode(url)
)
);
sink.listItem_();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ public String getUrl() {
return nonNullTextOrDefault(criterion.get("url"), null);
}

/**
* Gets the Path from the criterion, or {@code null} if not present.
*
* @return The Path from the criterion, or {@code null} if not present.
*/
public String getPath() {
return nonNullTextOrDefault(criterion.get("path"), null);
}

/**
* Gets the header from the criterion, or {@code null} if not present.
*
Expand Down

0 comments on commit 16630ff

Please sign in to comment.