Add basic proxy parser
This commit is contained in:
+17
-2
@@ -28,6 +28,7 @@
|
||||
#include "f2/function2.hpp"
|
||||
|
||||
#include "BloomFilter.h"
|
||||
#include "ProxyParser.h"
|
||||
|
||||
namespace uWS {
|
||||
|
||||
@@ -237,9 +238,9 @@ private:
|
||||
public:
|
||||
|
||||
/* We do this to prolong the validity of parsed headers by keeping only the fallback buffer alive */
|
||||
std::string &&salvageFallbackBuffer() {
|
||||
/*std::string &&salvageFallbackBuffer() {
|
||||
return std::move(fallback);
|
||||
}
|
||||
}*/
|
||||
|
||||
void *consumePostPadded(char *data, int length, void *user, fu2::unique_function<void *(void *, HttpRequest *)> &&requestHandler, fu2::unique_function<void *(void *, std::string_view, bool)> &&dataHandler, fu2::unique_function<void *(void *)> &&errorHandler) {
|
||||
|
||||
@@ -275,6 +276,9 @@ public:
|
||||
fallback.reserve(fallback.length() + maxCopyDistance + std::max<int>(MINIMUM_HTTP_POST_PADDING, sizeof(std::string)));
|
||||
fallback.append(data, maxCopyDistance);
|
||||
|
||||
// parse proxy here
|
||||
|
||||
|
||||
// break here on break
|
||||
std::pair<int, void *> consumed = fenceAndConsumePostPadded<true>(fallback.data(), (int) fallback.length(), user, &req, requestHandler, dataHandler);
|
||||
if (consumed.second != user) {
|
||||
@@ -318,6 +322,17 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// parse proxy here
|
||||
/* Parse proxy header */
|
||||
ProxyParser pp;
|
||||
auto [done, offset] = pp.parse({data, length});
|
||||
|
||||
if (!done) {
|
||||
|
||||
} else {
|
||||
printf("Proxy parser is done\n");
|
||||
}
|
||||
|
||||
std::pair<int, void *> consumed = fenceAndConsumePostPadded<false>(data, length, user, &req, requestHandler, dataHandler);
|
||||
if (consumed.second != user) {
|
||||
return consumed.second;
|
||||
|
||||
@@ -52,6 +52,13 @@ private:
|
||||
return (HttpResponseData<SSL> *) Super::getAsyncSocketData();
|
||||
}
|
||||
|
||||
/* If we have proxy support */
|
||||
#ifdef WITH_PROXY
|
||||
void getProxiedRemoteAddress() {
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Write an unsigned 32-bit integer in hex */
|
||||
void writeUnsignedHex(unsigned int value) {
|
||||
char buf[10];
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
|
||||
// implements PROXY v2 protocol
|
||||
|
||||
|
||||
|
||||
struct ProxyParser {
|
||||
int done = false;
|
||||
|
||||
// 16 byte IP, 2 byte port
|
||||
// 16 byte our IP, 2 byte our port
|
||||
|
||||
// return true when done, always return next offset for http parsing
|
||||
std::pair<bool, unsigned int> parse(std::string_view data) {
|
||||
|
||||
/* If already parsed, we're done */
|
||||
if (done) {
|
||||
return {true, 0};
|
||||
}
|
||||
|
||||
// we require 4 bytes to determine if this is http or not
|
||||
if (data.length() < 4) {
|
||||
// we are not done, buffer everything
|
||||
return {false, 0};
|
||||
} else {
|
||||
|
||||
|
||||
// is this proxy protocol?
|
||||
if (memcmp("\r\n\r\n", data.data(), 4) == 0) {
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
// it cannot be proxy protocol here, so we are done now
|
||||
done = true;
|
||||
return {true, 0};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
+1
-1
Submodule uSockets updated: 2ed0584e0b...fa16479609
Reference in New Issue
Block a user