summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2020-09-04 10:59:43 +0200
committerGitHub <noreply@github.com>2020-09-04 10:59:43 +0200
commitca5bf7c96534be3e295fe2e440fc980a75bd47b6 (patch)
treeb4c139803921e0d520b046305917be0cdadeaba4 /container-core
parent13212978faf3b5921a3e139c1512677f9b882591 (diff)
parent3c9de78274d5f7e5d7c7c19105e4925a91103e9e (diff)
Merge pull request #14257 from vespa-engine/bratseth/explicit-request-type
Allow setting a request type explicitly
Diffstat (limited to 'container-core')
-rw-r--r--container-core/abi-spec.json4
-rw-r--r--container-core/src/main/java/com/yahoo/container/jdisc/HttpResponse.java29
-rw-r--r--container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java1
3 files changed, 21 insertions, 13 deletions
diff --git a/container-core/abi-spec.json b/container-core/abi-spec.json
index 9292a946e82..244087e0271 100644
--- a/container-core/abi-spec.json
+++ b/container-core/abi-spec.json
@@ -464,7 +464,9 @@
"public java.lang.String getCharacterEncoding()",
"public void populateAccessLogEntry(com.yahoo.container.logging.AccessLogEntry)",
"public void complete()",
- "public java.lang.Iterable getLogValues()"
+ "public java.lang.Iterable getLogValues()",
+ "public void setRequestType(com.yahoo.jdisc.Request$RequestType)",
+ "public com.yahoo.jdisc.Request$RequestType getRequestType()"
],
"fields": [
"public static final java.lang.String DEFAULT_MIME_TYPE",
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/HttpResponse.java b/container-core/src/main/java/com/yahoo/container/jdisc/HttpResponse.java
index b4fcd044e50..dd03d72d97d 100644
--- a/container-core/src/main/java/com/yahoo/container/jdisc/HttpResponse.java
+++ b/container-core/src/main/java/com/yahoo/container/jdisc/HttpResponse.java
@@ -3,6 +3,7 @@ package com.yahoo.container.jdisc;
import com.yahoo.container.logging.AccessLogEntry;
import com.yahoo.jdisc.HeaderFields;
+import com.yahoo.jdisc.Request;
import com.yahoo.jdisc.Response;
import com.yahoo.processing.execution.Execution.Trace.LogValue;
@@ -18,21 +19,18 @@ import java.util.Collections;
*/
public abstract class HttpResponse {
- /**
- * Default response content type; text/plain.
- */
+ /** Default response content type; text/plain. */
public static final String DEFAULT_MIME_TYPE = "text/plain";
- /**
- * Default encoding/character set of a HTTP response; UTF-8.
- */
+ /** Default encoding/character set of a HTTP response; UTF-8. */
public static final String DEFAULT_CHARACTER_ENCODING = "UTF-8";
-
private final Response parentResponse;
+ private Request.RequestType requestType;
+
/**
- * Create a new HTTP response.
+ * Creates a new HTTP response
*
* @param status the HTTP status code to return with this response (may be changed later)
* @see Response
@@ -41,13 +39,11 @@ public abstract class HttpResponse {
parentResponse = com.yahoo.jdisc.http.HttpResponse.newInstance(status);
}
- /**
- * Marshal this response to the network layer. The caller is responsible for flushing and closing outputStream.
- */
+ /** Marshals this response to the network layer. The caller is responsible for flushing and closing outputStream. */
public abstract void render(OutputStream outputStream) throws IOException;
/**
- * The numeric HTTP status code, e.g. 200, 404 and so on.
+ * Returns the numeric HTTP status code, e.g. 200, 404 and so on.
*
* @return the numeric HTTP status code
*/
@@ -129,4 +125,13 @@ public abstract class HttpResponse {
return Collections::emptyIterator;
}
+ /** Sets the type classification of this request for metric collection purposes */
+ public void setRequestType(Request.RequestType requestType) { this.requestType = requestType; }
+
+ /**
+ * Returns the type classification of this request for metric collection purposes, or null if not set.
+ * When not set, the request type will be "read" for GET requests and "write" for other request methods.
+ */
+ public Request.RequestType getRequestType() { return requestType; }
+
}
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java
index 3a99ee7d0c6..ac1aa533201 100644
--- a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java
+++ b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java
@@ -78,6 +78,7 @@ public abstract class ThreadedHttpRequestHandler extends ThreadedRequestHandler
try {
channel = new LazyContentChannel(httpRequest, responseHandler, metric, log);
HttpResponse httpResponse = handle(httpRequest, channel);
+ request.setRequestType(httpResponse.getRequestType());
channel.setHttpResponse(httpResponse); // may or may not have already been done
render(httpRequest, httpResponse, channel, jdiscRequest.creationTime(TimeUnit.MILLISECONDS));
} catch (Exception e) {