Skip to content

Akka http server responds HEAD request as GET#4494

Merged
rabbah merged 4 commits into
apache:masterfrom
SugandhaAgrawal:head_get_akka
Jul 1, 2019
Merged

Akka http server responds HEAD request as GET#4494
rabbah merged 4 commits into
apache:masterfrom
SugandhaAgrawal:head_get_akka

Conversation

@SugandhaAgrawal
Copy link
Copy Markdown
Contributor

@SugandhaAgrawal SugandhaAgrawal commented May 27, 2019

Akka http client by default treats any http HEAD request as GET unless the configuration sets it otherwise. There are use cases where user expects HEAD to be responded as HEAD and without a response body unlike GET.

akka/akka-http#2088 mentions that the default is set to treat a HEAD as a GET request by the Akka client.

Description

Update the controller configuration to process HEAD and GET requests as they are expected.

Related issue and scope

  • I opened an issue to propose and discuss this change (#????)

My changes affect the following components

  • API
  • Controller
  • Message Bus (e.g., Kafka)
  • Loadbalancer
  • Invoker
  • Intrinsic actions (e.g., sequences, conductors)
  • Data stores (e.g., CouchDB)
  • Tests
  • Deployment
  • CLI
  • General tooling
  • Documentation

Types of changes

  • Bug fix (generally a non-breaking change which closes an issue).
  • Enhancement or new feature (adds new functionality).
  • Breaking change (a bug fix or enhancement which changes existing behavior).

Checklist:

  • I signed an Apache CLA.
  • I reviewed the style guides and followed the recommendations (Travis CI will check :).
  • I added tests to cover my changes.
  • My changes require further changes to the documentation.
  • I updated the documentation where necessary.

@chetanmeh
Copy link
Copy Markdown
Member

@SugandhaAgrawal I believe this is Akka HTTP Server setting and not related to client.

If we enable this would HEAD request still work in OpenWhisk or would fail. I presume so far they work just that internally executed as GET. However with this change would they stop working if route does not implement HEAD support?

@markusthoemmes
Copy link
Copy Markdown
Contributor

It'd be useful to get some context on the use-cases that trigger this issue.

@mbehrendt
Copy link
Copy Markdown

the context of this issue is actually quite straightforward: We have seen users trying to implement a web action that responds differently on HEAD than on GET. However, given __ow_method always had the same value (get), they weren't able to make that distinction in their action code.

@markusthoemmes
Copy link
Copy Markdown
Contributor

Got it, that makes sense. I guess @chetanmeh was confused (so was I) because the initial description talks about akka-https client not behaving as expected.

@chetanmeh is also right though that this is a breaking change as currently working HEAD requests will now fail.

@mbehrendt
Copy link
Copy Markdown

i wouldn't consider to be a breaking change per se, but rather a bug fix. It was just flatout wrong that when a HEAD request came in, __ow_method showed GET. Of course, if people relied on that bug to be true forever, they would break, but that is true for probably most other bug fixes as well :-)

@SugandhaAgrawal
Copy link
Copy Markdown
Contributor Author

@markusthoemmes I have the same thought as Michael's. I would say this is a bug fix. The breaking change in terms that the users need to change the implementation is fine but this is right way to handle the HEAD request.

@SugandhaAgrawal
Copy link
Copy Markdown
Contributor Author

SugandhaAgrawal commented May 28, 2019

@markusthoemmes The initial description does mean that akka http client isnt behaving as expected by default. It responds HEAD with a GET and that isnt the right response in my opinion.
In order to achieve this you need to set explicitly the value to off. My expectation was that the default should have been off or do you not find this as an expected result and correct?

@markusthoemmes
Copy link
Copy Markdown
Contributor

@SugandhaAgrawal the point is that it's the akka http server, not the client.

I'm indecisive on the bug fix vs. breaking change. I agree though that the amount of breakage is very small and arguably relying on undocumented/wrong behavior.

If @chetanmeh doesn't have strong feelings against it I'm fine merging this as-is. Otherwise we should take it to the dev-list.

@SugandhaAgrawal
Copy link
Copy Markdown
Contributor Author

@markusthoemmes Thanks for the correction, server ;)

Copy link
Copy Markdown
Member

@chetanmeh chetanmeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given web actions need to distinguish the request it makes sense for this change.

Would be good to have a test to assert this behavior i.e. _ow_method is indeed HEAD post this change

@SugandhaAgrawal
Copy link
Copy Markdown
Contributor Author

SugandhaAgrawal commented May 28, 2019

@chetanmeh I will include test in the next PR. I will add the output of my manual tests here for supporting the change.

@chetanmeh
Copy link
Copy Markdown
Member

If this fix is not very urgent would it be possible to include the test in this PR itself. I believe you can still enable this flag in your setups via system property

@rabbah
Copy link
Copy Markdown
Member

rabbah commented May 28, 2019

I agree this is a bug - the intended behavior is for the HEAD to reach the function just like OPTIONS. You'll need a system level tests (in WskWebActionsTests) that "curls" (i.e., makes an HTTP request to) the web action. I tested this patch locally and don't see a difference in behavior (a GET is posted with and without the patch). So +1 from me to include a test in this PR.

@rabbah
Copy link
Copy Markdown
Member

rabbah commented May 28, 2019

@chetanmeh I'm not sure if existing actions would fail --- at least not all. I suspect that you need actions which have already opted out of the default CORS response.

@rabbah
Copy link
Copy Markdown
Member

rabbah commented Jun 4, 2019

@SugandhaAgrawal any luck adding a test for this fix?

@SugandhaAgrawal SugandhaAgrawal changed the title Akka http client responds HEAD request as GET Akka http server responds HEAD request as GET Jun 5, 2019
@SugandhaAgrawal
Copy link
Copy Markdown
Contributor Author

@rabbah Unfortunately not. I was on vacation and returned today. Will work on it

@rabbah
Copy link
Copy Markdown
Member

rabbah commented Jun 5, 2019

welcome back!

Copy link
Copy Markdown
Member

@dubee dubee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SugandhaAgrawal, there should be some existing webaction tests that you can use as a template to test this one. Hopefully you can do a unit test for this, can't remember since I haven't looked at those in awhile. Integration test will definitely work though.

Nice find, BTW!

@SugandhaAgrawal SugandhaAgrawal force-pushed the head_get_akka branch 3 times, most recently from f2ba1ca to 321a7d5 Compare June 25, 2019 14:14
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jun 25, 2019

Codecov Report

Merging #4494 into master will decrease coverage by 3.58%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4494      +/-   ##
==========================================
- Coverage   83.65%   80.06%   -3.59%     
==========================================
  Files         174      174              
  Lines        8023     8023              
  Branches      552      552              
==========================================
- Hits         6712     6424     -288     
- Misses       1311     1599     +288
Impacted Files Coverage Δ
...core/database/cosmosdb/RxObservableImplicits.scala 0% <0%> (-100%) ⬇️
...core/database/cosmosdb/CosmosDBArtifactStore.scala 0% <0%> (-95.89%) ⬇️
...sk/core/database/cosmosdb/CosmosDBViewMapper.scala 0% <0%> (-92.6%) ⬇️
...whisk/core/database/cosmosdb/CosmosDBSupport.scala 0% <0%> (-74.08%) ⬇️
...abase/cosmosdb/CosmosDBArtifactStoreProvider.scala 4% <0%> (-52%) ⬇️
...re/database/cosmosdb/CollectionResourceUsage.scala 72.22% <0%> (-27.78%) ⬇️
...in/scala/org/apache/openwhisk/common/Counter.scala 40% <0%> (-20%) ⬇️
...penwhisk/core/database/cosmosdb/CosmosDBUtil.scala 81.81% <0%> (-15.16%) ⬇️
...nwhisk/core/database/cosmosdb/CosmosDBConfig.scala 94.11% <0%> (-5.89%) ⬇️
...in/scala/org/apache/openwhisk/common/Logging.scala 69.75% <0%> (-4.33%) ⬇️
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7d92be7...321a7d5. Read the comment docs.

Comment thread tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskWebActionsTests.scala Outdated
@SugandhaAgrawal
Copy link
Copy Markdown
Contributor Author

Screenshot 2019-06-27 at 09 45 52

Travis System Test

Comment thread tests/dat/actions/echo-web-http-head.js Outdated
@@ -0,0 +1,9 @@
// Licensed to the Apache Software Foundation (ASF) under one or more contributor
// license agreements; and to You under the Apache License, Version 2.0.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the long form license. We have to stop using the short form.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasnt aware of the 2 versions of license headers. I have made the update.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a recent change.

thanks for the update!

Copy link
Copy Markdown
Member

@rabbah rabbah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modulo the comment about auth.

val url = s"$host$testRoutePath/$namespace/default/$name"

assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, file, web = Some("true"), annotations = Map("require-whisk-auth" -> true.toJson))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can skip the require-whisk-auth annotation here.

}

val unauthorizedResponse = RestAssured.given().config(sslconfig).head(url)
unauthorizedResponse.statusCode shouldBe 401
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then remove this unless this is important to the test.

Copy link
Copy Markdown
Member

@rabbah rabbah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@SugandhaAgrawal
Copy link
Copy Markdown
Contributor Author

@rabbah Please merge this, if everything looks good!

@rabbah rabbah merged commit 740a4bf into apache:master Jul 1, 2019
@rabbah
Copy link
Copy Markdown
Member

rabbah commented Jul 1, 2019

Thanks @SugandhaAgrawal 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants