trungams / http-server Goto Github PK
View Code? Open in Web Editor NEWA simple HTTP/1.1 server implementation in C++
License: MIT License
A simple HTTP/1.1 server implementation in C++
License: MIT License
I just got this error while trying to make:
In file included from /home/pi/http-server/test/main.cc:10:
/home/pi/http-server/src/http_message.h:150:22: error: friend declaration of ‘std::string to_string(const simple_http_server::HttpResponse&, bool)’ specifies default arguments and isn’t a definition [-fpermissive]
150 | friend std::string to_string(const HttpResponse& request, bool send_content = true);
| ^~~~~~~~~
/home/pi/http-server/src/http_message.h:159:13: error: friend declaration of ‘std::string simple_http_server::to_string(const simple_http_server::HttpResponse&, bool)’ specifies default arguments and isn’t the only declaration [-fpermissive]
159 | std::string to_string(const HttpResponse& response, bool send_content);
| ^~~~~~~~~
/home/pi/http-server/src/http_message.h:150:22: note: previous declaration of ‘std::string simple_http_server::to_string(const simple_http_server::HttpResponse&, bool)’
150 | friend std::string to_string(const HttpResponse& request, bool send_content = true);
| ^~~~~~~~~
make[2]: *** [CMakeFiles/test_SimpleHttpServer.dir/build.make:82: CMakeFiles/test_SimpleHttpServer.dir/test/main.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:97: CMakeFiles/test_SimpleHttpServer.dir/all] Error 2
make: *** [Makefile:103: all] Error 2
I'm trying to send raw data with the server, but when I have null values in the content, the next bytes are all null. The file size is correct, but I assume it's due to the length header. This is how I did:
HttpResponse response(HttpStatusCode::Ok);
// send the framebuffer to the client as an arraybuffer
response.SetHeader("Content-Type", "arraybuffer");
const char *framebuffer_ptr = (const char *)framebuffer;
const std::string framebuffer_str = std::move(std::string(framebuffer_ptr, sizeof(framebuffer)));
response.SetContent(framebuffer_str);
// print framebuffer_str as hex values with 2 digits per byte
for (uint16_t i = 0; i < sizeof(framebuffer); i++)
{
std::cout << std::hex << std::setfill('0') << std::setw(2) << (int)framebuffer[i];
}
std::cout << framebuffer_str << std::endl;
The bytes are correctly printing in the console of the program, but on the client, only the first bytes are received:
server cout:
1d de ab 41 cd 26 e6 41 79 0 a4 6f 0 a3 84 0 a3 87 0 a3 35 0 86 46 0 92 6d 0 a3 7c 0 a4 7a 0 a4 7a 0 a4 70 0 a3
...
client :
1D DE AB 41 CD 26 E6 41 79 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...
I can't find by myself where the problem is, I know that all these pointers conversions are not the best choice, but since the server is minimal, there is no other type for adding content, and I think there is probably a condition where if the string have a null byte, stop sending data.
Hi, thank you for the great work.
I've encountered a seg fault after registering a new uri. The issue seems to related to memcpy
of response_string
. I think the 3rd argument should be the size of the response string to be copied instead of kMaxBufferSize
, or whichever is smaller.
http-server/src/http_server.cc
Lines 238 to 242 in 1c17136
this is a potential fix.
response_string
= to_string (http_response, http_request.method () != HttpMethod::HEAD);
const size_t res_len = response_string.length ();
size_t len_to_copy = (res_len < kMaxBufferSize)
? res_len : kMaxBufferSize;
memmove (raw_response->buffer, response_string.c_str (), len_to_copy);
raw_response->buffer[response_string.length ()] = '\0';
raw_response->length = response_string.length ();
I've forked the project to reproduce my error at this repo.
Hi, Thanks for your good work.
I'm really glad to see you and your project.
I have tried to compile this project in Msys to cross-compile.
But there is several errors.
Would you let me know which compiler I have to use?
I'm looking for your reply.
Thanks.
Best regards!!!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.