Skip to content

Crt http integration#2293

Closed
JonathanHenson wants to merge 21 commits intoaws:mainfrom
JonathanHenson:crt_http_integration_prototype
Closed

Crt http integration#2293
JonathanHenson wants to merge 21 commits intoaws:mainfrom
JonathanHenson:crt_http_integration_prototype

Conversation

@JonathanHenson
Copy link
Contributor

Added the CRT's HTTP client as an HTTP implementation. It's currently defalted to off, so this allows experimentation without disrupting any current defaults.

Check all that applies:

  • [ x] Did a review by yourself.
  • [ x] Added proper tests to cover this PR. (If tests are not applicable, explain.) Integration tests and existing http unit tests pass.
  • [x ] Checked if this PR is a breaking (APIs have been changed) change.
  • [ x] Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • [x ] Linux
  • [ x] Windows
  • Android
  • [ x] MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor

@SergeyRyabinin SergeyRyabinin left a comment

Choose a reason for hiding this comment

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

Overall looks good.

CRT submodule is checked-out to a simple commit hash not the hash of a released tag.
Also, a corresponding .sh script for customers using git without sub-modules is not updated.
You can use the following script to auto-pull latest released CRT (warning, it will reset/checkout . changes in your local /crt):

python3 scripts/ops/update_crt.py

requestOptions.onIncomingBody =
[response](Crt::Http::HttpStream&, const Crt::ByteCursor& body)
{
response->GetResponseBody().write((const char*)body.ptr, static_cast<long>(body.len));
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to check if the response body's stream has gone bad while writing?

docs talk about goodbit and badbit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I read through this, I went back and looked at all we do in the current libcurl client read callback. I need to rework the input stream section as well as this, and it's probably going to be big enough I have to break this out into another function. Will handle it in that refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We likely should. Both existing clients do not, so for the moment, I'd prefer not to alter anything we don't have to.

Copy link
Contributor

@graebm graebm left a comment

Choose a reason for hiding this comment

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

still reviewing, but here's what I've got at the end of today...

}

// initial check to see if we should avoid reading for the moment.
if (!m_rateLimiter || (m_rateLimiter && m_rateLimiter->ApplyCost(0) == std::chrono::milliseconds(0))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The CRT HTTP client is going to spin hot waiting for the rate limiter. Maybe should should sleep the thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is getting called from an aws-c-io event loop though?

Comment on lines +83 to +88
// this is safe because of the isAwsChunked branch above.
// I don't see a aws_byte_buf equivalent of memmove. This is lifted from the curl implementation.
memmove(originalBufferPos + hex.size() + 2, originalBufferPos, amountRead);
memmove(originalBufferPos + hex.size() + 2 + amountRead, "\r\n", 2);
memmove(originalBufferPos, hex.c_str(), hex.size());
memmove(originalBufferPos + hex.size(), "\r\n", 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

debatable: this aws-chunked stuff is a lot of copy/pasted finicky code. Consider a utility function that both the CurlHttpClient and CRTHttpClient can share

Aws::String hex = Aws::Utils::StringUtils::ToHexString(amountRead);
// this is safe because of the isAwsChunked branch above.
// I don't see a aws_byte_buf equivalent of memmove. This is lifted from the curl implementation.
memmove(originalBufferPos + hex.size() + 2, originalBufferPos, amountRead);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could skip a copy, and maybe have simpler code, if we knew in advance how long the aws-chunk prefix was going to be.

And we'd know the length if we wrote a fixed-length hex string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

? I don't know what you're asking but if it isn't altering the existing chunked encoding behavior at all, I'm not really interested in spending more time optimizing out a copy at the moment.

@jmklix jmklix added the needs-review This issue or pull request needs review from a core team member. label Feb 24, 2023
@jmklix
Copy link
Member

jmklix commented Mar 24, 2023

Merged here: #2376

@jmklix jmklix closed this Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review This issue or pull request needs review from a core team member.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants