Skip to content

Commit 64b8c2f

Browse files
committed
Parse URL path manually
1 parent a9545fb commit 64b8c2f

58 files changed

Lines changed: 64 additions & 22338 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/upstream-utils.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ jobs:
109109
./libuv.py clone
110110
./libuv.py copy-src
111111
./libuv.py format-patch
112+
- name: Run llhttp.py
113+
run: |
114+
cd upstream_utils
115+
./llhttp.py clone
116+
./llhttp.py copy-src
117+
./llhttp.py format-patch
112118
- name: Run llvm.py
113119
run: |
114120
cd upstream_utils

ThirdPartyNotices.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ LLVM wpiutil/src/main/native/thirdparty/llvm
2121
wpiutil/src/test/native/cpp/llvm/
2222
JSON for Classic C++ wpiutil/src/main/native/thirdparty/json
2323
libuv wpinet/src/main/native/thirdparty/libuv/
24+
llhttp wpinet/src/main/native/thirdparty/llhttp
2425
sigslot wpiutil/src/main/native/thirdparty/sigslot
2526
tcpsockets wpinet/src/main/native/thirdparty/tcpsockets
2627
MPack wpiutil/src/main/native/thirdparty/mpack
@@ -407,6 +408,33 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
407408
IN THE SOFTWARE.
408409

409410

411+
==============
412+
llhttp License
413+
==============
414+
MIT License
415+
416+
Copyright © 2018 Fedor Indutny
417+
418+
Permission is hereby granted, free of charge, to any person obtaining a
419+
copy of this software and associated documentation files (the
420+
"Software"), to deal in the Software without restriction, including
421+
without limitation the rights to use, copy, modify, merge, publish,
422+
distribute, sublicense, and/or sell copies of the Software, and to permit
423+
persons to whom the Software is furnished to do so, subject to the
424+
following conditions:
425+
426+
The above copyright notice and this permission notice shall be included
427+
in all copies or substantial portions of the Software.
428+
429+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
430+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
431+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
432+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
433+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
434+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
435+
USE OR OTHER DEALINGS IN THE SOFTWARE.
436+
437+
410438
==============================================================================
411439
sigslot License
412440
==============================================================================

ntcore/src/main/native/cpp/NetworkServer.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <utility>
1616
#include <vector>
1717

18-
#include <ada.h>
19-
2018
#include "IConnectionList.hpp"
2119
#include "InstanceImpl.hpp"
2220
#include "Log.hpp"
@@ -126,23 +124,9 @@ void NetworkServer::ServerConnection::ConnectionClosed() {
126124

127125
void NetworkServer::ServerConnection4::ProcessRequest() {
128126
DEBUG1("HTTP request: '{}'", m_request.GetUrl());
129-
auto url = ada::parse(m_request.GetUrl());
130-
if (!url) {
131-
// failed to parse URL
132-
SendError(400);
133-
return;
134-
}
135-
136-
std::string_view path;
137-
if (url->get_pathname_length() > 0) {
138-
path = url->get_pathname();
139-
}
127+
auto [path, query] = wpi::util::split(m_request.GetUrl(), "?");
140128
DEBUG4("path: \"{}\"", path);
141129

142-
std::string_view query;
143-
if (url->has_search()) {
144-
query = url->get_search();
145-
}
146130
DEBUG4("query: \"{}\"\n", query);
147131

148132
const bool isGET = m_request.GetMethod() == HTTP_GET;
@@ -162,11 +146,7 @@ void NetworkServer::ServerConnection4::ProcessRequest() {
162146

163147
void NetworkServer::ServerConnection4::ProcessWsUpgrade() {
164148
// get name from URL
165-
auto url = ada::parse(m_request.GetUrl());
166-
std::string_view path;
167-
if (url->get_pathname_length() > 0) {
168-
path = url->get_pathname();
169-
}
149+
auto [path, query] = wpi::util::split(m_request.GetUrl(), "?");
170150
DEBUG4("path: '{}'", path);
171151

172152
wpi::util::SmallString<128> nameBuf;

shared/bazel/rules/cc_rules.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ def third_party_cc_lib_helper(
189189
include_root,
190190
src_root = None,
191191
src_excludes = [],
192-
visibility = None,
193-
**kwargs):
192+
defines = [],
193+
visibility = None):
194194
"""
195195
Helper for src / headers pairs that aren't directly compiled, but rather pulled into a bigger library.
196196
@@ -213,9 +213,9 @@ def third_party_cc_lib_helper(
213213
include_root + "/**",
214214
]),
215215
includes = [include_root],
216+
defines = defines,
216217
strip_include_prefix = include_root,
217218
visibility = visibility,
218-
**kwargs
219219
)
220220

221221
pkg_files(

simulation/halsim_ws_server/src/main/native/cpp/HALSimHttpConnection.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <string>
1010
#include <string_view>
1111

12-
#include <ada.h>
1312
#include <llhttp.h>
1413
#include <uv.h>
1514

@@ -150,17 +149,7 @@ void HALSimHttpConnection::SendFileResponse(int code, std::string_view codeText,
150149
}
151150

152151
void HALSimHttpConnection::ProcessRequest() {
153-
auto url = ada::parse(m_request.GetUrl());
154-
if (!url) {
155-
// failed to parse URL
156-
MySendError(400, "Invalid URL");
157-
return;
158-
}
159-
160-
std::string_view path;
161-
if (url->get_pathname_length() > 0) {
162-
path = url->get_pathname();
163-
}
152+
auto [path, query] = wpi::util::split(m_request.GetUrl(), "?");
164153

165154
if (m_request.GetMethod() == HTTP_GET && wpi::util::starts_with(path, '/') &&
166155
!wpi::util::contains(path, "..") && !wpi::util::contains(path, "//")) {

upstream_utils/ada.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

upstream_utils/ada_patches/0001-Undefine-ADA_INCLUDE_URL_PATTERN.patch

Lines changed: 0 additions & 22 deletions
This file was deleted.

upstream_utils/ada_patches/0002-Use-std-expected.patch

Lines changed: 0 additions & 133 deletions
This file was deleted.

upstream_utils/llhttp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def copy_upstream_src(wpilib_root: Path):
1818
shutil.rmtree(wpinet / d, ignore_errors=True)
1919
(wpinet / d).mkdir(parents=True, exist_ok=True)
2020

21-
subprocess.check_call(["npm", "i"], shell=True)
22-
subprocess.check_call(["npm", "run", "build"], shell=True)
21+
subprocess.check_call("npm i", shell=True)
22+
subprocess.check_call("npm run build", shell=True)
2323
# Copy files into allwpilib
2424
shutil.copyfile(
2525
"build/llhttp.h",

0 commit comments

Comments
 (0)