Skip to content

Commit 03c448c

Browse files
committed
refactor(core, tests): encapsulate method and uri fields in Request
- Replaced direct field access with `setMethod` and `setUri` to improve encapsulation. - Adjusted `RequestTest` to use setters for `method` and `uri`.
1 parent 79fec90 commit 03c448c

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

core/src/main/java/com/predic8/membrane/core/http/Request.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class Request extends Message {
4747

4848
private static final HashSet<String> methodsWithoutBody = Sets.newHashSet(METHOD_GET, METHOD_HEAD, METHOD_CONNECT);
4949

50-
String method;
51-
String uri;
50+
private String method;
51+
private String uri;
5252

5353
@Override
5454
protected void parseStartLine(InputStream in) throws IOException {
@@ -306,6 +306,12 @@ public Builder post(URIFactory uriFactory, String url) throws URISyntaxException
306306
return method(Request.METHOD_POST).url(uriFactory, url);
307307
}
308308

309+
/**
310+
* For tests and special cases where URIs do not contain weird characters.
311+
* @param url
312+
* @return
313+
* @throws URISyntaxException
314+
*/
309315
public Builder post(String url) throws URISyntaxException {
310316
return post(new URIFactory(), url);
311317
}

core/src/test/java/com/predic8/membrane/core/http/RequestTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ private AbstractBody readMessageAndGetBody() throws IOException, EndOfStreamExce
393393

394394
public Request create(String method, String uri, String protocol, Header header, InputStream in) throws IOException {
395395
var r = new Request();
396-
r.method = method;
397-
r.uri = uri;
396+
r.setMethod(method);
397+
r.setUri(uri);
398398
if (!protocol.startsWith("HTTP/"))
399399
throw new RuntimeException("Unknown protocol '" + protocol + "'");
400400
r.version = protocol.substring(5);

0 commit comments

Comments
 (0)