Skip to content

swift: add conversion from Request to headers#288

Merged
rebello95 merged 2 commits intomasterfrom
swift-add-conversion-from-request-to-headers
Jul 23, 2019
Merged

swift: add conversion from Request to headers#288
rebello95 merged 2 commits intomasterfrom
swift-add-conversion-from-request-to-headers

Conversation

@rebello95
Copy link
Copy Markdown
Contributor

@rebello95 rebello95 commented Jul 23, 2019

Adds converters to go from Request to a set of headers that upstream Envoy understands.

This will be utilized by the request logic in the Envoy class.

Previous consideration: #275

Signed-off-by: Michael Rebello me@michaelrebello.com

Adds converters to go from `Request` to a set of headers that upstream Envoy understands.

This will be utilized by the request logic in the `Envoy` class.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
/// - returns: Outbound headers to send with an HTTP request.
func makeOutboundHeaders() -> [String: String] {
var headers = self.headers
.filter { !$0.key.hasPrefix(kRestrictedHeaderPrefix) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm guessing this will silently drop headers with the restricted prefix - did we decide to do this instead of throw?

Another option would be to simply abort the request and pass control to the onError handler.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see there's another PR which throws.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Though I just read the comment on that one that we don't want to have to try the builder. What's our current thinking?

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.

We discussed further over Slack, and decided that it wasn't worth making the builder for adding headers throwable since this would greatly reduce the ergonomics of using it. URLSession allows for setting these headers silently, which is what we prefer to do here as well

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.

Another option would be to simply abort the request and pass control to the onError handler.

We could do this, though personally I'd prefer to keep it simple and strip those headers for the time being

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah, this was a super annoying realization because Swift/ObjC doesn't have a kinder runtime exception concept which this would be a good use case for since it'll be a way for us to complain to the user that they did something unexpected. While I do think that we should throw for this case, I feel it's worse to make the user handle errors for which they have already accounted for.

The alternatives here is to compromise on the builder object:

  1. Breaking the builder pattern by returning a pair (builder + error)
  2. Have the build return a pair (request + error)
  3. Straight crashing the application (the nuclear rocket version in Swift/ObjC of a runtime exception)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That all makes sense. I think silently dropping them is reasonable for now.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
@rebello95 rebello95 requested review from buildbreaker and goaway July 23, 2019 16:36
@rebello95 rebello95 merged commit f28bc96 into master Jul 23, 2019
@rebello95 rebello95 deleted the swift-add-conversion-from-request-to-headers branch July 23, 2019 19:58
buildbreaker pushed a commit that referenced this pull request Jul 24, 2019
Mirrors: #288

Adds converters to go from Request to a set of headers that upstream Envoy understands.

This will be utilized by the request logic in the Envoy class.

For an explanation of how to fill out the fields, please see the relevant section
in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/master/PULL_REQUESTS.md)

Description: kotlin: add conversion from Request to headers
Risk Level: low
Testing: unit
Docs Changes: n/a
Release Notes: n/a
[Optional Fixes #Issue]
[Optional Deprecated:]
jpsim pushed a commit to envoyproxy/envoy that referenced this pull request Nov 28, 2022
Mirrors: envoyproxy/envoy-mobile#288

Adds converters to go from Request to a set of headers that upstream Envoy understands.

This will be utilized by the request logic in the Envoy class.

For an explanation of how to fill out the fields, please see the relevant section
in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/master/PULL_REQUESTS.md)

Description: kotlin: add conversion from Request to headers
Risk Level: low
Testing: unit
Docs Changes: n/a
Release Notes: n/a
[Optional Fixes #Issue]
[Optional Deprecated:]

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit to envoyproxy/envoy that referenced this pull request Nov 29, 2022
Mirrors: envoyproxy/envoy-mobile#288

Adds converters to go from Request to a set of headers that upstream Envoy understands.

This will be utilized by the request logic in the Envoy class.

For an explanation of how to fill out the fields, please see the relevant section
in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/master/PULL_REQUESTS.md)

Description: kotlin: add conversion from Request to headers
Risk Level: low
Testing: unit
Docs Changes: n/a
Release Notes: n/a
[Optional Fixes #Issue]
[Optional Deprecated:]

Signed-off-by: JP Simard <jp@jpsim.com>
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.

3 participants