Skip to content

Commit 02faa22

Browse files
authored
Enable to connect to the host that hosting on non 443 port (#37)
MsH3ConnectionOpen has hard-coded port number "443". But there are serving not 443 port of QUIC implementations are, like nghttp2.org, quic.tech. https://github.com/quicwg/base-drafts/wiki/Implementations And, I confirmed that succeeded in connecting those hosts by original msquic implementation. The patch makes msh3 support QUIC with non 443 port also.
1 parent 8e20cf2 commit 02faa22

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
run: /usr/local/lib/msh3app www.cloudflare.com
4343
- name: GET www.google.com
4444
run: /usr/local/lib/msh3app www.google.com
45+
- name: GET nghttp2.org:4433
46+
run: /usr/local/lib/msh3app nghttp2:4433
4547
build-windows-openssl:
4648
permissions:
4749
contents: read
@@ -80,6 +82,9 @@ jobs:
8082
- name: GET www.google.com
8183
run: |
8284
& 'C:/Program Files/msh3/lib/msh3app' www.google.com
85+
- name: GET nghttp2.org:4433
86+
run: |
87+
& 'C:/Program Files/msh3/lib/msh3app' nghttp2.org:4433
8388
build-windows-schannel:
8489
permissions:
8590
contents: read
@@ -112,3 +117,6 @@ jobs:
112117
- name: GET www.google.com
113118
run: |
114119
& 'C:/Program Files/msh3/lib/msh3app' www.google.com
120+
- name: GET nghttp2.org:4433
121+
run: |
122+
& 'C:/Program Files/msh3/lib/msh3app' nghttp2.org:4433

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const size_t HeadersCount = sizeof(Headers)/sizeof(MSH3_HEADER);
2525

2626
MSH3_API* Api = MsH3ApiOpen();
2727
if (Api) {
28-
MSH3_CONNECTION* Connection = MsH3ConnectionOpen(Api, Host, Unsecure);
28+
MSH3_CONNECTION* Connection = MsH3ConnectionOpen(Api, Host, Port, Unsecure);
2929
if (Connection) {
3030
MSH3_REQUEST* Request = MsH3RequestOpen(Connection, &Callbacks, NULL, Headers, HeadersCount);
3131
// ...
@@ -60,4 +60,5 @@ cmake --build .
6060
msh3app outlook.office.com
6161
msh3app www.cloudflare.com
6262
msh3app www.google.com
63+
msh3app nghttp2.org:4433
6364
```

lib/msh3.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ MSH3_CALL
6868
MsH3ConnectionOpen(
6969
MSH3_API* Handle,
7070
const char* ServerName,
71+
uint16_t Port,
7172
bool Unsecure
7273
)
7374
{
7475
auto Reg = (MsQuicRegistration*)Handle;
75-
auto H3 = new(std::nothrow) MsH3Connection(*Reg, ServerName, 443, Unsecure);
76+
auto H3 = new(std::nothrow) MsH3Connection(*Reg, ServerName, Port, Unsecure);
7677
if (!H3 || QUIC_FAILED(H3->GetInitStatus())) {
7778
delete H3;
7879
return nullptr;

msh3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ MSH3_CALL
4343
MsH3ConnectionOpen(
4444
MSH3_API* Handle,
4545
const char* ServerName,
46+
uint16_t Port,
4647
bool Unsecure
4748
);
4849

tool/msh3_app.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,34 @@ int MSH3_CALL main(int argc, char **argv) {
4545
}
4646

4747
const char* Host = "outlook.office.com";
48+
int Port = 443;
49+
char *givenHost = NULL;
4850
const char* Path = "/";
4951
bool Unsecure = false;
5052
uint32_t Count = 1;
5153

52-
if (argc > 1) Host = argv[1];
54+
if (argc > 1) {
55+
if(strrchr(argv[1], ':') != NULL) {
56+
const int len = (int)strlen(argv[1]);
57+
givenHost = (char *)calloc(len + sizeof(char), sizeof(char));
58+
if (givenHost == NULL) {
59+
printf("Failed to allocate memory\n");
60+
return -1;
61+
}
62+
#ifdef _WIN32
63+
int cnt = sscanf_s(argv[1], "%[^:]:%d", givenHost, len, &Port);
64+
#else
65+
int cnt = sscanf(argv[1], "%[^:]:%d", givenHost, &Port);
66+
#endif
67+
if (cnt != 2) {
68+
printf("Failed to parse server address\n");
69+
return -1;
70+
}
71+
Host = givenHost;
72+
} else {
73+
Host = argv[1];
74+
}
75+
}
5376
if (argc > 2) Path = argv[2];
5477
if (argc > 3 && !strcmp(argv[3], "unsecure")) Unsecure = true;
5578
if (argc > 4) Count = (uint32_t)atoi(argv[4]);
@@ -65,11 +88,11 @@ int MSH3_CALL main(int argc, char **argv) {
6588
};
6689
const size_t HeadersCount = sizeof(Headers)/sizeof(MSH3_HEADER);
6790

68-
printf("HTTP/3 GET https://%s%s\n\n", Host, Path);
91+
printf("HTTP/3 GET https://%s:%d%s\n\n", Host, Port, Path);
6992

7093
auto Api = MsH3ApiOpen();
7194
if (Api) {
72-
auto Connection = MsH3ConnectionOpen(Api, Host, Unsecure);
95+
auto Connection = MsH3ConnectionOpen(Api, Host, (uint16_t)Port, Unsecure);
7396
if (Connection) {
7497
for (uint32_t i = 0; i < Count; ++i) {
7598
auto Request = MsH3RequestOpen(Connection, &Callbacks, (void*)(size_t)(i+1), Headers, HeadersCount);
@@ -83,5 +106,7 @@ int MSH3_CALL main(int argc, char **argv) {
83106
MsH3ApiClose(Api);
84107
}
85108

109+
free(givenHost);
110+
86111
return 0;
87112
}

0 commit comments

Comments
 (0)