aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/http/http_client.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-11-17 22:46:42 -0800
committerGarrett D'Amore <garrett@damore.org>2020-11-17 22:49:59 -0800
commitcda4885676f009e2e7f2ad5e6c52743efc8b8924 (patch)
tree62dfc33e0559cbf84efb014dd17b687247cadda8 /src/supplemental/http/http_client.c
parent04974cc135ca461d8fce50fa8def0ca5fe13b101 (diff)
downloadnng-cda4885676f009e2e7f2ad5e6c52743efc8b8924.tar.gz
nng-cda4885676f009e2e7f2ad5e6c52743efc8b8924.tar.bz2
nng-cda4885676f009e2e7f2ad5e6c52743efc8b8924.zip
Centralize the scheme handling for HTTP schemes.
Diffstat (limited to 'src/supplemental/http/http_client.c')
-rw-r--r--src/supplemental/http/http_client.c38
1 files changed, 8 insertions, 30 deletions
diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c
index 2efb97a8..36446b63 100644
--- a/src/supplemental/http/http_client.c
+++ b/src/supplemental/http/http_client.c
@@ -100,30 +100,14 @@ nni_http_client_init(nni_http_client **cp, const nni_url *url)
int rv;
nni_http_client *c;
nng_url my_url;
+ const char * scheme;
- // Rewrite URLs to either TLS or TCP.
- memcpy(&my_url, url, sizeof(my_url));
- if ((strcmp(url->u_scheme, "http") == 0) ||
- (strcmp(url->u_scheme, "ws") == 0)) {
- my_url.u_scheme = "tcp";
- } else if ((strcmp(url->u_scheme, "https") == 0) ||
- (strcmp(url->u_scheme, "wss") == 0)) {
- my_url.u_scheme = "tls+tcp";
- } else if ((strcmp(url->u_scheme, "ws4") == 0) ||
- (strcmp(url->u_scheme, "http4") == 0)) {
- my_url.u_scheme = "tcp4";
- } else if ((strcmp(url->u_scheme, "ws6") == 0) ||
- (strcmp(url->u_scheme, "http6") == 0)) {
- my_url.u_scheme = "tcp6";
- } else if ((strcmp(url->u_scheme, "wss4") == 0) ||
- (strcmp(url->u_scheme, "https4") == 0)) {
- my_url.u_scheme = "tls+tcp4";
- } else if ((strcmp(url->u_scheme, "wss6") == 0) ||
- (strcmp(url->u_scheme, "https6") == 0)) {
- my_url.u_scheme = "tls+tcp6";
- } else {
+ if ((scheme = nni_http_stream_scheme(url->u_scheme)) == NULL) {
return (NNG_EADDRINVAL);
}
+ // Rewrite URLs to either TLS or TCP.
+ memcpy(&my_url, url, sizeof(my_url));
+ my_url.u_scheme = (char *) scheme;
if (strlen(url->u_hostname) == 0) {
// We require a valid hostname.
@@ -153,20 +137,14 @@ nni_http_client_init(nni_http_client **cp, const nni_url *url)
int
nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls)
{
- int rv;
- rv = nni_stream_dialer_set(c->dialer, NNG_OPT_TLS_CONFIG, &tls,
- sizeof(tls), NNI_TYPE_POINTER);
- return (rv);
+ return (nng_stream_dialer_set_ptr(c->dialer, NNG_OPT_TLS_CONFIG, tls));
}
int
nni_http_client_get_tls(nni_http_client *c, nng_tls_config **tlsp)
{
- size_t sz = sizeof(*tlsp);
- int rv;
- rv = nni_stream_dialer_get(
- c->dialer, NNG_OPT_TLS_CONFIG, tlsp, &sz, NNI_TYPE_POINTER);
- return (rv);
+ return (nng_stream_dialer_get_ptr(
+ c->dialer, NNG_OPT_TLS_CONFIG, (void **) tlsp));
}
int