Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Implement HTTP request in offchain workers #3447
Implements the currently-unimplemented API.
I'm opening this PR as a draft because I'm going to be away for a bit, and I encourage someone to finish it if they want.
The only thing that's not implemented is a small TODO to fix: we unwrap if we fail to initialize the
In order to implement this, I had to properly document/define how the API is to be used.
From the point of view of the offchain worker, the order in which functions must be called on an HTTP request is: initialization (
Most steps can be skipped (for example, reading the body implicitly waits for the answer), but changing the order of the steps is generally not allowed. The exceptions are: you are still allowed to wait for answer or read response headers after having started to read the body, as long as EOF hasn't been returned.
As side changes, I also:
Falling back to http when https fails should be exploitable by a downgrade attack, right? Hope I am not missing something.
@mxinden well, so the thing is that no
I think it's a pretty niche case, but might be worth handling anyway.