mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Make major improvements to redbean
- lua server pages - lua http library - http v0.9 support - request uri parsing - fork failure recovery - accelerated redirects - http pipelining support - lenient message framing - html / uri / js escaping - fix shutdown signal handling
This commit is contained in:
parent
6b90ff60cd
commit
09bcfa23d5
23 changed files with 2208 additions and 581 deletions
|
@ -19,16 +19,18 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "net/http/http.h"
|
||||
|
||||
long ParseContentLength(const struct HttpRequest *req, const char *p) {
|
||||
long i, r, n = 0;
|
||||
for (i = req->headers[kHttpContentLength].a;
|
||||
i < req->headers[kHttpContentLength].b; ++i) {
|
||||
if (isdigit(p[i])) {
|
||||
if (!__builtin_mul_overflow(n, 10, &r) &&
|
||||
!__builtin_add_overflow(r, p[i] - '0', &r)) {
|
||||
n = r;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parses Content-Length header.
|
||||
*
|
||||
* @return -1 on invalid or overflow, otherwise >=0 value
|
||||
*/
|
||||
ssize_t ParseContentLength(const char *s, size_t n) {
|
||||
int i, r = 0;
|
||||
if (!n) return -1;
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (!isdigit(s[i])) return -1;
|
||||
if (__builtin_mul_overflow(r, 10, &r)) return -1;
|
||||
if (__builtin_add_overflow(r, s[i] - '0', &r)) return -1;
|
||||
}
|
||||
return n;
|
||||
return r;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue