Skip to content

feat: support custom-headers#455

Merged
tusharmath merged 13 commits intotailcallhq:mainfrom
wrath-of-god:custom-headers
Oct 14, 2023
Merged

feat: support custom-headers#455
tusharmath merged 13 commits intotailcallhq:mainfrom
wrath-of-god:custom-headers

Conversation

@wrath-of-god
Copy link
Copy Markdown
Contributor

@wrath-of-god wrath-of-god commented Oct 9, 2023

/claim #377
fixes #377
Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh to address and fix linting issues.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly (if applicable).
  • I have performed a self-review of my own code.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 9, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (0450061) 84.20% compared to head (2ee7e4d) 85.94%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #455      +/-   ##
==========================================
+ Coverage   84.20%   85.94%   +1.74%     
==========================================
  Files          50       50              
  Lines        4532     4554      +22     
==========================================
+ Hits         3816     3914      +98     
+ Misses        716      640      -76     
Files Coverage Δ
src/blueprint/from_config.rs 96.60% <100.00%> (+0.06%) ⬆️
src/config/server.rs 80.00% <ø> (+12.00%) ⬆️
src/http/server.rs 73.01% <100.00%> (+73.01%) ⬆️
src/http/server_context.rs 92.30% <100.00%> (+92.30%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wrath-of-god
Copy link
Copy Markdown
Contributor Author

@tusharmath @amitksingh1490 do not able to test this? any recommendation/direction?

@tusharmath
Copy link
Copy Markdown
Contributor

We will need tests over here as coverage drops quite significantly. I think a little bit of refactoring of the functions can make this piece more testable without requiring mocks.

Test Specifications:

  1. We should be able to view all errors with every invalid header name or value.
  2. Invalid header error should be composed with Blueprint generation errors.

@tusharmath
Copy link
Copy Markdown
Contributor

Let me know if there are any other questions @wrath-of-god Feel free to hop on our discord to get more help if needed.

@wrath-of-god wrath-of-god marked this pull request as ready for review October 11, 2023 04:14
@tusharmath
Copy link
Copy Markdown
Contributor

I think this is great! We could clean this up a little bit though.

  • Create a blueprint::Server that contains a processed version of config::Server
  • This way Blueprint contains processed a validated HeaderMap which can be passed around everywhere.

@@ -0,0 +1,17 @@
#> server-sdl
schema @server(baseURL: "https://jsonplaceholder.typicode.com", setHeaders: [{key: "🤣", value: "a"}]) {
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.

Suggested change
schema @server(baseURL: "https://jsonplaceholder.typicode.com", setHeaders: [{key: "🤣", value: "a"}]) {
schema @server(baseURL: "https://jsonplaceholder.typicode.com", responseHeaders: [{key: "🤣", value: "a"}]) {

How about calling it responseHeaders ?


#> client-sdl
type Failure
@error(message: "Parsing failed because of invalid HTTP header name", trace: ["schema", "@server", "setHeaders"])
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.

  • Add tests for invalid Http HeaderValue
  • Add tests for multiple failures ie, if multiple headers are invalid, we should be able to show all of them in errors.

@wrath-of-god wrath-of-god force-pushed the custom-headers branch 2 times, most recently from dd1b38b to e5743cb Compare October 12, 2023 18:18
Comment on lines +27 to 40
pub struct Server {
pub allowed_headers: Option<HashSet<String>>,
pub base_url: Option<String>,
pub enable_apollo_tracing: Option<bool>,
pub enable_cache_control_header: Option<bool>,
pub enable_graphiql: Option<String>,
pub enable_http_cache: Option<bool>,
pub enable_introspection: Option<bool>,
pub enable_query_validation: Option<bool>,
pub enable_response_validation: Option<bool>,
pub global_response_timeout: Option<i64>,
pub port: Option<u16>,
pub upstream: Upstream,
pub vars: BTreeMap<String, String>,
pub batch: Option<crate::config::Batch>,
pub response_headers: HeaderMap,
}
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.

We can drop Option The Server in blueprint should contain the final values. Which means basically no option types, HeaderMap instead of KeyValues, Urls instead of String etc. It should be safe to use blueprint::Server.


Valid::Ok(())
server
}
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.

Can `impl Fromconfig::Server for blueprint::Server

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be tryFrom and return Valid

},
}
}
fn validate_both<A1>(self, other: Result<A1, ValidationError<E>>) -> Valid<(A, A1), E> {
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.

Did we use this function anywhere?

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.

yes

@wrath-of-god
Copy link
Copy Markdown
Contributor Author

@tusharmath Please review before conflicts come 🙏 .

@tusharmath tusharmath changed the title feat:custom-headers feat: support custom-headers Oct 14, 2023
@tusharmath tusharmath merged commit 1635866 into tailcallhq:main Oct 14, 2023
@tusharmath tusharmath mentioned this pull request Oct 14, 2023
5 tasks
digital-phoenix pushed a commit to digital-phoenix/tailcall that referenced this pull request Oct 15, 2023
* commit '69814ec785fef5d5cf3d4ba925a4910e0a09715e':
  refactor: use default batch settings if group_by is used (tailcallhq#497)
  refactor: use blueprint server throughout (tailcallhq#495)
  feat: hostname config in server (tailcallhq#493)
  Load YAML & JSON formats via CLI (tailcallhq#467)
  fix(deps): update rust crate regex to 1.10.1 (tailcallhq#491)
  fix(deps): update rust crate async-trait to 0.1.74 (tailcallhq#492)
  feat: support custom-headers (tailcallhq#455)
  fix: n + 1 issue (tailcallhq#487)
  fix: mandatory file path
  refactor: drop key from group by (tailcallhq#484)
  feature: load multiple configs via CLI (tailcallhq#482)
  feat: merge right on config (tailcallhq#476)
  doc: example update
  fix: upstream setting keys should be optional (tailcallhq#474)
  refactor: prerequisite to test multi sdl (tailcallhq#475)
  refactor: use btreeset where duplicates are not allowed (tailcallhq#478)
  fix: info loss in const serialisation (tailcallhq#477)
  feat: support to configure http settings (tailcallhq#388)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom response headers

3 participants