summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-09-02 16:42:10 +0200
committerJon Bratseth <bratseth@gmail.com>2020-09-02 16:42:10 +0200
commit3c9de78274d5f7e5d7c7c19105e4925a91103e9e (patch)
tree1e0027dc08663b890ecdc9b68b6543fadb394691 /container-core
parent5a10a3cc2bbad52d783e75a92c1527e33e976fe9 (diff)
Allow setting a request type explicitly
This lets handler authors control the requestType explicitly by setting it on the HttpResponse, which is useful to avoid misclassification of POST requests to reading handlers as writes.
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) {