| 1 | package com.renomad.minum.web; | |
| 2 | ||
| 3 | import java.util.Objects; | |
| 4 | ||
| 5 | import static com.renomad.minum.web.BodyProcessor.determineBoundaryValue; | |
| 6 | ||
| 7 | /** | |
| 8 | * An implementation of {@link IRequest}. | |
| 9 | * Contains implementations for behaviors dealing with the request data. | |
| 10 | */ | |
| 11 | public final class Request implements IRequest { | |
| 12 | ||
| 13 | private final Headers headers; | |
| 14 | private final RequestLine requestLine; | |
| 15 | private Body body; | |
| 16 | private final String remoteRequester; | |
| 17 | private final ISocketWrapper socketWrapper; | |
| 18 | private final IBodyProcessor bodyProcessor; | |
| 19 | private boolean hasStartedReadingBody; | |
| 20 | ||
| 21 | /** | |
| 22 | * Constructor for a HTTP request. | |
| 23 | * @param remoteRequester This is the remote address making the request | |
| 24 | */ | |
| 25 | public Request(Headers headers, | |
| 26 | RequestLine requestLine, | |
| 27 | String remoteRequester, | |
| 28 | ISocketWrapper socketWrapper, | |
| 29 | IBodyProcessor bodyProcessor, | |
| 30 | boolean hasStartedReadingBody | |
| 31 | ) { | |
| 32 | this.headers = headers; | |
| 33 | this.requestLine = requestLine; | |
| 34 | this.remoteRequester = remoteRequester; | |
| 35 | this.socketWrapper = socketWrapper; | |
| 36 | this.bodyProcessor = bodyProcessor; | |
| 37 | this.hasStartedReadingBody = hasStartedReadingBody; | |
| 38 | } | |
| 39 | ||
| 40 | ||
| 41 | @Override | |
| 42 | public Headers getHeaders() { | |
| 43 |
1
1. getHeaders : replaced return value with null for com/renomad/minum/web/Request::getHeaders → TIMED_OUT |
return headers; |
| 44 | } | |
| 45 | ||
| 46 | @Override | |
| 47 | public RequestLine getRequestLine() { | |
| 48 |
1
1. getRequestLine : replaced return value with null for com/renomad/minum/web/Request::getRequestLine → TIMED_OUT |
return requestLine; |
| 49 | } | |
| 50 | ||
| 51 | @Override | |
| 52 | public Body getBody() { | |
| 53 |
1
1. getBody : negated conditional → TIMED_OUT |
if (hasStartedReadingBody) { |
| 54 | throw new WebServerException("The InputStream in Request has already been accessed for reading, preventing body extraction from stream." + | |
| 55 | " If intending to use getBody(), use it exclusively"); | |
| 56 | } | |
| 57 |
1
1. getBody : negated conditional → TIMED_OUT |
if (body == null) { |
| 58 | body = bodyProcessor.extractData(socketWrapper.getInputStream(), headers); | |
| 59 | } | |
| 60 |
1
1. getBody : replaced return value with null for com/renomad/minum/web/Request::getBody → TIMED_OUT |
return body; |
| 61 | } | |
| 62 | ||
| 63 | @Override | |
| 64 | public String getRemoteRequester() { | |
| 65 |
1
1. getRemoteRequester : replaced return value with "" for com/renomad/minum/web/Request::getRemoteRequester → TIMED_OUT |
return remoteRequester; |
| 66 | } | |
| 67 | ||
| 68 | @Override | |
| 69 | public ISocketWrapper getSocketWrapper() { | |
| 70 |
1
1. getSocketWrapper : removed call to com/renomad/minum/web/Request::checkForExistingBody → TIMED_OUT |
checkForExistingBody(); |
| 71 | hasStartedReadingBody = true; | |
| 72 |
1
1. getSocketWrapper : replaced return value with null for com/renomad/minum/web/Request::getSocketWrapper → TIMED_OUT |
return socketWrapper; |
| 73 | } | |
| 74 | ||
| 75 | @Override | |
| 76 | public boolean equals(Object o) { | |
| 77 |
2
1. equals : replaced boolean return with false for com/renomad/minum/web/Request::equals → TIMED_OUT 2. equals : negated conditional → KILLED |
if (this == o) return true; |
| 78 |
3
1. equals : negated conditional → TIMED_OUT 2. equals : replaced boolean return with true for com/renomad/minum/web/Request::equals → TIMED_OUT 3. equals : negated conditional → TIMED_OUT |
if (o == null || getClass() != o.getClass()) return false; |
| 79 | Request request = (Request) o; | |
| 80 |
8
1. equals : negated conditional → TIMED_OUT 2. equals : negated conditional → TIMED_OUT 3. equals : negated conditional → TIMED_OUT 4. equals : negated conditional → TIMED_OUT 5. equals : negated conditional → TIMED_OUT 6. equals : negated conditional → TIMED_OUT 7. equals : negated conditional → TIMED_OUT 8. equals : replaced boolean return with true for com/renomad/minum/web/Request::equals → KILLED |
return hasStartedReadingBody == request.hasStartedReadingBody && Objects.equals(headers, request.headers) && Objects.equals(requestLine, request.requestLine) && Objects.equals(body, request.body) && Objects.equals(remoteRequester, request.remoteRequester) && Objects.equals(socketWrapper, request.socketWrapper) && Objects.equals(bodyProcessor, request.bodyProcessor); |
| 81 | } | |
| 82 | ||
| 83 | @Override | |
| 84 | public int hashCode() { | |
| 85 |
1
1. hashCode : replaced int return with 0 for com/renomad/minum/web/Request::hashCode → TIMED_OUT |
return Objects.hash(headers, requestLine, body, remoteRequester, socketWrapper, bodyProcessor, hasStartedReadingBody); |
| 86 | } | |
| 87 | ||
| 88 | @Override | |
| 89 | public String toString() { | |
| 90 |
1
1. toString : replaced return value with "" for com/renomad/minum/web/Request::toString → TIMED_OUT |
return "Request{" + |
| 91 | "headers=" + headers + | |
| 92 | ", requestLine=" + requestLine + | |
| 93 | ", body=" + body + | |
| 94 | ", remoteRequester='" + remoteRequester + '\'' + | |
| 95 | ", socketWrapper=" + socketWrapper + | |
| 96 | ", hasStartedReadingBody=" + hasStartedReadingBody + | |
| 97 | '}'; | |
| 98 | } | |
| 99 | ||
| 100 | @Override | |
| 101 | public Iterable<UrlEncodedKeyValue> getUrlEncodedIterable() { | |
| 102 |
1
1. getUrlEncodedIterable : removed call to com/renomad/minum/web/Request::checkForExistingBody → TIMED_OUT |
checkForExistingBody(); |
| 103 |
1
1. getUrlEncodedIterable : negated conditional → TIMED_OUT |
if (!headers.contentType().contains("application/x-www-form-urlencoded")) { |
| 104 | throw new WebServerException("This request was not sent with a content type of application/x-www-form-urlencoded. The content type was: " + headers.contentType()); | |
| 105 | } | |
| 106 |
1
1. getUrlEncodedIterable : replaced return value with Collections.emptyList for com/renomad/minum/web/Request::getUrlEncodedIterable → TIMED_OUT |
return bodyProcessor.getUrlEncodedDataIterable(getSocketWrapper().getInputStream(), getHeaders().contentLength()); |
| 107 | } | |
| 108 | ||
| 109 | /** | |
| 110 | * This method is for verifying that the body is null, and throwing an exception | |
| 111 | * if not. Several of the methods in this class depend on the InputStream not | |
| 112 | * having been read already - if the body was read, then the InputStream is finished, | |
| 113 | * and any further reading would be incorrect. | |
| 114 | */ | |
| 115 | private void checkForExistingBody() { | |
| 116 |
1
1. checkForExistingBody : negated conditional → TIMED_OUT |
if (body != null) { |
| 117 | throw new WebServerException("Requesting this after getting the body with getBody() will result in incorrect behavior. " + | |
| 118 | "If you intend to work with the Request at this level, do not use getBody"); | |
| 119 | } | |
| 120 |
1
1. checkForExistingBody : negated conditional → TIMED_OUT |
if (hasStartedReadingBody) { |
| 121 | throw new WebServerException("The InputStream has begun processing elsewhere. Results are invalid."); | |
| 122 | } | |
| 123 | } | |
| 124 | ||
| 125 | @Override | |
| 126 | public Iterable<StreamingMultipartPartition> getMultipartIterable() { | |
| 127 |
1
1. getMultipartIterable : removed call to com/renomad/minum/web/Request::checkForExistingBody → TIMED_OUT |
checkForExistingBody(); |
| 128 | String contentType = getHeaders().contentType(); | |
| 129 | String boundaryValue = determineBoundaryValue(contentType); | |
| 130 | ||
| 131 |
1
1. getMultipartIterable : negated conditional → TIMED_OUT |
if (boundaryValue.isBlank()) { |
| 132 | throw new BadRequestException("Boundary value was blank. Header was: " + contentType); | |
| 133 | } | |
| 134 | ||
| 135 |
1
1. getMultipartIterable : replaced return value with Collections.emptyList for com/renomad/minum/web/Request::getMultipartIterable → TIMED_OUT |
return bodyProcessor.getMultiPartIterable(getSocketWrapper().getInputStream(), boundaryValue, getHeaders().contentLength()); |
| 136 | } | |
| 137 | ||
| 138 | @Override | |
| 139 | public boolean hasAccessedBody() { | |
| 140 |
3
1. hasAccessedBody : negated conditional → TIMED_OUT 2. hasAccessedBody : negated conditional → TIMED_OUT 3. hasAccessedBody : replaced boolean return with true for com/renomad/minum/web/Request::hasAccessedBody → TIMED_OUT |
return hasStartedReadingBody || body != null; |
| 141 | } | |
| 142 | ||
| 143 | @Override | |
| 144 | public IBodyProcessor getBodyProcessor() { | |
| 145 |
1
1. getBodyProcessor : replaced return value with null for com/renomad/minum/web/Request::getBodyProcessor → TIMED_OUT |
return bodyProcessor; |
| 146 | } | |
| 147 | ||
| 148 | @Override | |
| 149 | public boolean isHasStartedReadingBody() { | |
| 150 |
2
1. isHasStartedReadingBody : replaced boolean return with true for com/renomad/minum/web/Request::isHasStartedReadingBody → TIMED_OUT 2. isHasStartedReadingBody : replaced boolean return with false for com/renomad/minum/web/Request::isHasStartedReadingBody → TIMED_OUT |
return hasStartedReadingBody; |
| 151 | } | |
| 152 | } | |
Mutations | ||
| 43 |
1.1 |
|
| 48 |
1.1 |
|
| 53 |
1.1 |
|
| 57 |
1.1 |
|
| 60 |
1.1 |
|
| 65 |
1.1 |
|
| 70 |
1.1 |
|
| 72 |
1.1 |
|
| 77 |
1.1 2.2 |
|
| 78 |
1.1 2.2 3.3 |
|
| 80 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 85 |
1.1 |
|
| 90 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 106 |
1.1 |
|
| 116 |
1.1 |
|
| 120 |
1.1 |
|
| 127 |
1.1 |
|
| 131 |
1.1 |
|
| 135 |
1.1 |
|
| 140 |
1.1 2.2 3.3 |
|
| 145 |
1.1 |
|
| 150 |
1.1 2.2 |