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 |
mfazekas
left a comment
There was a problem hiding this comment.
👍 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.
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
| // 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.
Same as android: store as regexp in add and just test here
| addCustomHeader( | ||
| headerName: string, | ||
| headerValue: string, | ||
| options?: { urlPattern?: string }, |
There was a problem hiding this comment.
Maybe call urlRegexp as we're expecting a regular epxression?
There was a problem hiding this comment.
sounds good, updated
… modules to caller scope for better defined boundaries - rename urlPattern to urlRegexp
44e4145 to
83c3dd8
Compare
hey when I tried doing this the method signature in the |
mfazekas
left a comment
There was a problem hiding this comment.
Pls fix CI, otherwise looks good to me
| '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.
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.
oops mb bad commit - was testing this out locally
There was a problem hiding this comment.
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
|
hey @mfazekas - are these changes good to merge in? |
Description
Added
your featurethat allows adding custom headers based on url pattern matching, as per discussion hereMapbox.addCustomHeaderwith optionalurlPatternkey which defines the regex string for when there is a match against therequest.urlit will add the custom header value header and value.Checklist
CONTRIBUTING.mdyarn generatein the root folder/exampleapp./example)Screenshot OR Video