You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2019/07/01 15:02:45 UTC
[incubator-openwhisk] branch master updated: Allow actions to
respond to HEAD requests (#4494)
This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 740a4bf Allow actions to respond to HEAD requests (#4494)
740a4bf is described below
commit 740a4bf17561edb920a5d57de18b583da5736d18
Author: Su <su...@gmail.com>
AuthorDate: Mon Jul 1 17:02:38 2019 +0200
Allow actions to respond to HEAD requests (#4494)
---
.../controller/src/main/resources/application.conf | 10 +++++++++
tests/dat/actions/echo-web-http-head.js | 23 +++++++++++++++++++
.../core/cli/test/WskWebActionsTests.scala | 26 ++++++++++++++++++++++
3 files changed, 59 insertions(+)
diff --git a/core/controller/src/main/resources/application.conf b/core/controller/src/main/resources/application.conf
index 36e91f6..6116789 100644
--- a/core/controller/src/main/resources/application.conf
+++ b/core/controller/src/main/resources/application.conf
@@ -62,6 +62,16 @@ akka.http {
# This must be greater than the request timeout.
idle-timeout = 70s
+ # Description:
+ # Enables/disables automatic handling of HEAD requests.
+ # If this setting is enabled the server dispatches HEAD requests as GET
+ # requests to the application and automatically strips off all message
+ # bodies from outgoing responses.
+ # Note that, even when this setting is off the server will never send
+ # out message bodies on responses to HEAD requests.
+ # Default value today is on, hence need to explicitly set this to off
+ transparent-head-requests = off
+
parsing {
# This indirectly puts a bound on the name of entities
# 8k matches nginx default
diff --git a/tests/dat/actions/echo-web-http-head.js b/tests/dat/actions/echo-web-http-head.js
new file mode 100644
index 0000000..6029496
--- /dev/null
+++ b/tests/dat/actions/echo-web-http-head.js
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function main(params) {
+ return {
+ statusCode: 200,
+ headers: { 'Request-type': params.__ow_method }
+ };
+}
diff --git a/tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskWebActionsTests.scala b/tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskWebActionsTests.scala
index c2187b7..fb6783d 100644
--- a/tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskWebActionsTests.scala
+++ b/tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskWebActionsTests.scala
@@ -305,6 +305,32 @@ class WskWebActionsTests extends TestHelpers with WskTestHelpers with RestUtil w
response.body.asByteArray shouldBe Base64.getDecoder().decode(png)
}
+ /**
+ * Tests web action for HEAD requests
+ */
+ it should "create a web action making a HEAD request" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
+ val name = "webactionHead"
+ val file = Some(TestUtils.getTestActionFilename("echo-web-http-head.js"))
+ val host = getServiceURL()
+ val url = s"$host$testRoutePath/$namespace/default/$name"
+
+ assetHelper.withCleaner(wsk.action, name) { (action, _) =>
+ action.create(name, file, web = Some("true"))
+ }
+
+ val authorizedResponse = RestAssured
+ .given()
+ .config(sslconfig)
+ .auth()
+ .preemptive()
+ .basic(wskprops.authKey.split(":")(0), wskprops.authKey.split(":")(1))
+ .head(url)
+
+ authorizedResponse.statusCode shouldBe 200
+ authorizedResponse.body.asString() shouldBe ""
+ authorizedResponse.getHeader("Request-type") shouldBe "head"
+ }
+
private val subdomainRegex = Seq.fill(WhiskProperties.getPartsInVanitySubdomain)("[a-zA-Z0-9]+").mkString("-")
private lazy val (vanitySubdomain, vanityNamespace, makeTestSubject) = {