Closed DarknessRdg closed 3 years ago
Hello @DarknessRdg,
How about using this version of the Request function or use a custom HTTP client?
With best regards,
Elmer
I can't use Request constructor because I would need to implement my own MessageCreator in order to use that constructor.
I could solve my problem using your approach of a custom HTTP client. My solution was to ininherit NetworkHttpClient
and override makeRequest
to replace the Request URL to a new URL with my custom domain.
class CustomDomainNetworkHttpClient(domain: String) : NetworkHttpClient() {
private val domain: String
init {
val http = Regex("http[s]?://")
this.domain = if (domain.contains(http)) domain else "http://$domain"
}
override fun reliableRequest(request: Request?): Response {
if (request != null)
return super.reliableRequest(requestToDomainRequest(request))
return super.reliableRequest(request)
}
override fun makeRequest(request: Request?): Response {
if (request != null) {
val requestToDomain = requestToDomainRequest(request)
return super.makeRequest(requestToDomain)
}
return super.makeRequest(request)
}
private fun requestToDomainRequest(request: Request) = Request(
request.method,
changeUrlDomain(request.constructURL().toString())
)
private fun changeUrlDomain(url: String): String {
return Regex("http[s]?://.+\\.com").replace(url, domain)
}
}
I don't know if it's the best approach to handle it.
Thank you for your help !
Nice!!
Thank you for taking the time to share your solution!
Issue Summary
So, this is my scenery: I'm using mockserver on my tests and I need to change twilio host so I can also use
mockrserver
with twilio. It means I need to changehttps://api.twilio.com
for another host such ashttp://127.0.0.1
.Nowadays, the only API I'm using is to send SMS messages, with
MessageCreator
. I have looked into the code, and it seems the host is places as hardcode when a newResquest
instanciated.Does anyone know how to change it or even if is possible to change this host using SMS API ?
Steps to Reproduce
val from = PhoneNumber(twilioPhoneNumber) val to = PhoneNumber(phoneNumber.phone) Message.creator(to, from, "Hello World").create()