-
-
Notifications
You must be signed in to change notification settings - Fork 687
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
This would solve...
I encountered an issue when changing the target URL, specifically due to a difference in the trailing slash.
For example:
http://example.comvs.http://example.com/
After reviewing the implementation in MockAgent, I realized the root cause:
Lines 56 to 64 in 4608ef1
| get (origin) { | |
| let dispatcher = this[kMockAgentGet](origin) | |
| if (!dispatcher) { | |
| dispatcher = this[kFactory](origin) | |
| this[kMockAgentSet](origin, dispatcher) | |
| } | |
| return dispatcher | |
| } |
It uses the full URL string as a key in a map.
Therefore, the presence or absence of the trailing slash significantly affects the lookup behavior.
The implementation should look like...
To address this, it might be possible to leverage the ignoreTrailingSlash option provided by MockAgent.
The implementation could look like this:
get (origin) {
const key = this[kIgnoreTrailingSlash]? origin.replace(/\/$/, '') : origin;
let dispatcher = this[kMockAgentGet](key)
if (!dispatcher) {
dispatcher = this[kFactory](key)
this[kMockAgentSet](key, dispatcher)
}
return dispatcher
} Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request