cosmopolitan/net/http/http.h

134 lines
4.5 KiB
C
Raw Normal View History

2020-06-15 14:18:57 +00:00
#ifndef COSMOPOLITAN_LIBC_HTTP_HTTP_H_
#define COSMOPOLITAN_LIBC_HTTP_HTTP_H_
#include "libc/alg/alg.h"
#include "libc/time/struct/tm.h"
2020-06-15 14:18:57 +00:00
#define kHttpGet 0
#define kHttpHead 1
#define kHttpPost 2
#define kHttpPut 3
#define kHttpDelete 4
#define kHttpOptions 5
#define kHttpConnect 6
#define kHttpTrace 7
#define kHttpCopy 8
#define kHttpLock 9
#define kHttpMerge 10
#define kHttpMkcol 11
#define kHttpMove 12
#define kHttpNotify 13
#define kHttpPatch 14
#define kHttpReport 15
#define kHttpUnlock 16
2020-06-15 14:18:57 +00:00
#define kHttpAccept 0
#define kHttpAcceptCharset 1
#define kHttpAcceptEncoding 2
#define kHttpAcceptLanguage 3
#define kHttpAge 4
#define kHttpAllow 5
#define kHttpAuthorization 6
#define kHttpCacheControl 7
#define kHttpChunked 8
#define kHttpClose 9
#define kHttpConnection 10
#define kHttpContentBase 11
#define kHttpContentEncoding 12
#define kHttpContentLanguage 13
#define kHttpContentLength 14
#define kHttpContentLocation 15
#define kHttpContentMd5 16
#define kHttpContentRange 17
#define kHttpContentType 18
#define kHttpDate 19
#define kHttpEtag 20
#define kHttpExpires 21
#define kHttpFrom 22
#define kHttpHost 23
#define kHttpIfMatch 24
#define kHttpIfModifiedSince 25
#define kHttpIfNoneMatch 26
#define kHttpIfRange 27
#define kHttpIfUnmodifiedSince 28
#define kHttpKeepAlive 29
#define kHttpMaxForwards 30
#define kHttpPragma 31
#define kHttpProxyAuthenticate 32
#define kHttpProxyAuthorization 33
#define kHttpProxyConnection 34
#define kHttpRange 35
#define kHttpReferer 36
#define kHttpTransferEncoding 37
#define kHttpUpgrade 38
#define kHttpUserAgent 39
#define kHttpVia 40
#define kHttpLocation 41
#define kHttpPublic 42
#define kHttpRetryAfter 43
#define kHttpServer 44
#define kHttpVary 45
#define kHttpWarning 46
#define kHttpWwwAuthenticate 47
#define kHttpLastModified 48
#define kHttpCookie 49
#define kHttpTrailer 50
#define kHttpTe 51
#define kHttpDnt 52
#define kHttpExpect 53
#define kHttpContentDisposition 54
#define kHttpContentDescription 55
#define kHttpOrigin 56
#define kHttpUpgradeInsecureRequests 57
#define kHttpHeadersMax 58
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
2020-06-15 14:18:57 +00:00
struct HttpRequestSlice {
short a, b;
2020-06-15 14:18:57 +00:00
};
struct HttpRequest {
int i, t, a, method;
struct HttpRequestSlice k;
struct HttpRequestSlice uri;
struct HttpRequestSlice version;
struct HttpRequestSlice scratch;
struct HttpRequestSlice headers[kHttpHeadersMax];
struct HttpRequestHeaders {
size_t n;
struct HttpRequestHeader {
struct HttpRequestSlice k;
struct HttpRequestSlice v;
} * p;
} xheaders;
2020-06-15 14:18:57 +00:00
};
extern const char kHttpMethod[17][8];
int GetHttpHeader(const char *, size_t);
int GetHttpMethod(const char *, size_t);
void InitHttpRequest(struct HttpRequest *);
void DestroyHttpRequest(struct HttpRequest *);
int ParseHttpRequest(struct HttpRequest *, const char *, size_t);
int NegotiateHttpRequest(int, const char *, uint32_t *, char *, uint32_t *,
2020-06-15 14:18:57 +00:00
uint32_t *, bool, long double);
ssize_t ParseContentLength(const char *, size_t);
char *FormatHttpDateTime(char[hasatleast 30], struct tm *);
bool ParseHttpRange(const char *, size_t, long, long *, long *);
unsigned ParseHttpVersion(const char *, size_t);
int64_t ParseHttpDateTime(const char *, size_t);
const char *GetHttpReason(int);
const char *GetHttpHeaderName(int);
char *DecodeLatin1(const char *, size_t, size_t *);
bool IsValidHttpToken(const char *, size_t);
char *EncodeHttpHeaderValue(const char *, size_t, size_t *);
char *VisualizeControlCodes(const char *, size_t, size_t *);
char *IndentLines(const char *, size_t, size_t *, size_t);
Make major improvements to redbean and libraries The most exciting improvement is dynamic pages will soon be able to use the executable itself as an object store. it required a heroic technique for overcoming ETXTBSY restrictions which lets us open the executable in read/write mode, which means (1) wa can restore the APE header, and (2) we can potentially containerize redbean extension code so that modules you download for your redbean online will only impact your redbean. Here's a list of breaking changes to redbean: - Remove /tool/net/ prefix from magic ZIP paths - GetHeader() now returns NIL if header is absent Here's a list of fixes and enhancements to redbean: - Support 64-bit ZIP archives - Record User-Agent header in logs - Add twelve error handlers to accept() - Display octal st_mode on listing page - Show ZIP file comments on listing page - Restore APE MZ header on redbean startup - Track request count on redbean index page - Report server uptime on redbean index page - Don't bind server socket using SO_REUSEPORT - Fix #151 where Lua LoadAsset() could free twice - Report rusage accounting when workers exit w/ -vv - Use ZIP iattr field as text/plain vs. binary hint - Add ParseUrl() API for parsing things like a.href - Add ParseParams() API for parsing HTTP POST bodies - Add IsAcceptablePath() API for checking dots, etc. - Add IsValidHttpToken() API for validating sane ASCII - Add IsAcceptableHostPort() for validating HOST[:PORT] - Send 400 response to HTTP/1.1 requests without a Host - Send 403 response if ZIP or file isn't other readable - Add virtual hosting that tries prepending Host to path - Route requests based on Host in Request-URI if present - Host routing will attempt to remove or add the www. prefix - Sign-extend UNIX timestamps and don't adjust FileTime zone Here's some of the improvements made to Cosmopolitan Libc: - Fix ape.S indentation - Improve consts.sh magnums - Write pretty good URL parser - Improve rusage accounting apis - Bring mremap() closer to working - Added ZIP APIs which will change - Check for overflow in reallocarray() - Remove overly fancy linkage in strerror() - Fix GDB attach on crash w/ OpenBSD msyscall() - Make sigqueue() portable to most UNIX distros - Make integer serialization macros more elegant - Bring back 34x tprecode8to16() performance boost - Make malloc() more resilient to absurdly large sizes
2021-04-18 18:34:59 +00:00
bool IsAcceptablePath(const char *, size_t);
bool IsAcceptableHostPort(const char *, size_t);
2020-06-15 14:18:57 +00:00
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_HTTP_HTTP_H_ */