Skip to content

Commit

Permalink
Support any HTTP method
Browse files Browse the repository at this point in the history
It's now possible to use redbean Fetch() with arbitrary HTTP methods,
e.g. LIST which is used by Hashicorp. There's an eight char limit and
uppercase canonicalization still happens. This change also includes a
better function for launching a browser tab, that won't deadlock on a
headless workstation running Debian.

Closes #1107
  • Loading branch information
jart committed Feb 22, 2024
1 parent 29eac8e commit ad3944a
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 412 deletions.
30 changes: 0 additions & 30 deletions net/http/gethttpmethod.gperf

This file was deleted.

196 changes: 0 additions & 196 deletions net/http/gethttpmethod.inc

This file was deleted.

32 changes: 11 additions & 21 deletions net/http/http.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
#ifndef COSMOPOLITAN_LIBC_HTTP_HTTP_H_
#define COSMOPOLITAN_LIBC_HTTP_HTTP_H_
#include "libc/serialize.h"
#include "libc/time/struct/tm.h"

#define kHttpRequest 0
#define kHttpResponse 1

#define kHttpGet 1
#define kHttpHead 2
#define kHttpPost 3
#define kHttpPut 4
#define kHttpDelete 5
#define kHttpOptions 6
#define kHttpConnect 7
#define kHttpTrace 8
#define kHttpCopy 9
#define kHttpLock 10
#define kHttpMerge 11
#define kHttpMkcol 12
#define kHttpMove 13
#define kHttpNotify 14
#define kHttpPatch 15
#define kHttpReport 16
#define kHttpUnlock 17
#define kHttpGet READ32LE("GET")
#define kHttpHead READ32LE("HEAD")
#define kHttpPost READ32LE("POST")
#define kHttpPut READ32LE("PUT")
#define kHttpDelete READ64LE("DELETE\0")
#define kHttpOptions READ64LE("OPTIONS")
#define kHttpConnect READ64LE("CONNECT")
#define kHttpTrace READ64LE("TRACE\0\0")

#define kHttpStateStart 0
#define kHttpStateMethod 1
Expand Down Expand Up @@ -168,14 +160,13 @@ struct HttpMessage {
int i, a, status;
unsigned char t;
unsigned char type;
unsigned char method;
unsigned char version;
uint64_t method;
struct HttpSlice k;
struct HttpSlice uri;
struct HttpSlice scratch;
struct HttpSlice message;
struct HttpSlice headers[kHttpHeadersMax];
struct HttpSlice xmethod;
struct HttpHeaders xheaders;
};

Expand All @@ -187,13 +178,11 @@ struct HttpUnchunker {
};

extern const char kHttpToken[256];
extern const char kHttpMethod[18][8];
extern const bool kHttpRepeatable[kHttpHeadersMax];

const char *GetHttpReason(int);
const char *GetHttpHeaderName(int);
int GetHttpHeader(const char *, size_t);
int GetHttpMethod(const char *, size_t);
void InitHttpMessage(struct HttpMessage *, int);
void DestroyHttpMessage(struct HttpMessage *);
int ParseHttpMessage(struct HttpMessage *, const char *, size_t);
Expand All @@ -202,6 +191,7 @@ int64_t ParseContentLength(const char *, size_t);
char *FormatHttpDateTime(char[hasatleast 30], struct tm *);
bool ParseHttpRange(const char *, size_t, long, long *, long *);
int64_t ParseHttpDateTime(const char *, size_t);
uint64_t ParseHttpMethod(const char *, size_t);
bool IsValidHttpToken(const char *, size_t);
bool IsValidCookieValue(const char *, size_t);
bool IsAcceptablePath(const char *, size_t);
Expand Down
40 changes: 0 additions & 40 deletions net/http/khttpmethod.c

This file was deleted.

Loading

0 comments on commit ad3944a

Please sign in to comment.