-
-
Notifications
You must be signed in to change notification settings - Fork 914
feat: Add options parameter to Mapbox.addCustomHeader method #3988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add options parameter to Mapbox.addCustomHeader method #3988
Conversation
…ttern to add header only when there is a regex pattern match against urlPattern - Add example usage of addCustomHeader to example App.js and disable escape character check for regex characters
I know contributions guidelines detail how to generate components docs but it doesn't look like |
Yes Mapbox.md and CustomHttpHeaders.md not generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 awesome, thanks much for working on it
headers[entry.key] = entry.value.headerValue | ||
} | ||
} catch (e: PatternSyntaxException) { | ||
Log.w(LOG_TAG, e.localizedMessage ?: "Error converting ${options?.urlPattern} to regex") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer Logger.e as that's visible in react-native side as well
Also it would be better to convert to regex in add, as we have a few adds and a lot of tests
ios/RNMBX/CustomHttpHeaders.swift
Outdated
// Check if a URL pattern exists. | ||
if let pattern = options.urlPattern { | ||
do { | ||
let regex = try NSRegularExpression(pattern: pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as android: store as regexp in add and just test here
src/RNMBXModule.ts
Outdated
addCustomHeader( | ||
headerName: string, | ||
headerValue: string, | ||
options?: { urlPattern?: string }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call urlRegexp
as we're expecting a regular epxression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, updated
… modules to caller scope for better defined boundaries - rename urlPattern to urlRegexp
44e4145
to
83c3dd8
Compare
hey @mfazekas - I had to try a different approach and added a new method |
Thanks much looks good to me. Not sure if it's possible to add a new TypeScript method to RNMBXModule, which would call the appropriate native method.
|
hey when I tried doing this the method signature in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls fix CI, otherwise looks good to me
.eslintrc.js
Outdated
'no-return-assign': 0, | ||
'no-underscore-dangle': [0], | ||
'no-await-in-loop': 0, | ||
'no-useless-escape': ['error', { allowRegexCharacters: ['-'] }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI fails:
Error: .eslintrc.js:
Configuration for rule "no-useless-escape" is invalid:
Value [{"allowRegexCharacters":["-"]}] should NOT have more than 0 items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops mb bad commit - was testing this out locally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @mfazekas - have fixed eslint and unit tests for CI, I think the other tests that fail are related to requiring mapbox tokens? not sure
…-parameter-to-add-custom-header
Description
Added
your feature
that allows adding custom headers based on url pattern matching, as per discussion hereMapbox.addCustomHeader
with optionalurlPattern
key which defines the regex string for when there is a match against therequest.url
it will add the custom header value header and value.Checklist
CONTRIBUTING.md
yarn generate
in the root folder/example
app./example
)Screenshot OR Video