Comments (1)
We have a fork of the code that supports query params but that hasn't been integrated into this repo:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <haywire.h>
#include "route_compare_method.h"
typedef struct hw_route_token_st {
hw_string string;
int start;
} hw_route_token;
inline void update_route_token(hw_route_token* result, hw_string* value, int length, int start) {
result->string.value = value;
result->string.length = length;
result->start = start;
}
void hw_route_next_token(hw_string* url, int start, hw_route_token* result) {
// when url is /
if (url->value[start] == '/' && url->length == 1){
update_route_token(result, url->value + start, 1, start);
}
else if (url->value[start] == '?') {
update_route_token(result, NULL, 0, -1);
}
else {
while (start < url->length && url->value[start] == '/') {
start++;
}
int end = start;
while (end < url->length && url->value[end] != '/' && url->value[end] != '?') {
end++;
}
if (end != start) {
update_route_token(result, url->value + start, end - start - 1, start);
}
else {
update_route_token(result, NULL, 0, -1);
}
}
}
int hw_route_compare_method(hw_string* url, char* route)
{
int equal = 0;
int match = 0;
// TODO route should probably be a hw_string* too
hw_string hw_route;
hw_route.value = route;
hw_route.length = strlen(route);
hw_route_token route_token;
hw_route_token request_token;
hw_route_next_token(url, 0, &request_token);
hw_route_next_token(&hw_route, 0, &route_token);
while (route_token.string.value != NULL && request_token.string.value != NULL)
{
if (route_token.string.value[0] == '*') {
// wildcard support: any route fragment marked with '*' matches the corresponding url fragment
equal = 1;
}
else
{
match = hw_strcmp(&route_token.string, &request_token.string);
if (!match)
{
equal = 1;
}
else
{
equal = 0;
break;
}
}
hw_route_next_token(url, request_token.start + request_token.string.length + 1, &request_token);
hw_route_next_token(&hw_route, route_token.start + route_token.string.length + 1, &route_token);
}
if (!equal)
{
match = hw_strcmp(url, &hw_route);
if (!match)
{
equal = 1;
}
}
if ((route_token.string.value == NULL && request_token.string.value != NULL) || (route_token.string.value != NULL && request_token.string.value == NULL))
{
equal = 0;
}
return equal;
}
from haywire.
Related Issues (20)
- Default configuration
- haywire_hello_world sometimes segfaults HOT 4
- build fails on OS X 10.11.3 with latest Xcode HOT 2
- [Discussion] Running the benchmarks
- Reduce malloc() and free() calls HOT 2
- Error building on Windows 2012 R2 Standard (x64) and MVSC2015 HOT 1
- Errors building ib Ubuntu HOT 1
- How about haywire vs h2o or mongoose? HOT 1
- remote peer address
- i run hello world sample on windows(visual studio), when i change thread count > 0, sample can't run HOT 1
- compiling with gyp HOT 3
- Is there any plan to support websocket?
- Should the print body function (hw_print_body) be in Hawyire.h?
- Assertion failed: (server->loop == client->loop) when starting IPC worker threads
- Create a Makefile to replace make.sh HOT 1
- Investigate using mlock
- Split the multi-event loop IPC and REUSEPORT multi-threading from http_server
- Assertion failed: ... does not yet support other types of streams
- pointer being freed was not allocated
- Use the fastest Http Parser picoparser
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from haywire.