make header field names case insensitive
This commit is contained in:
parent
584aad56b8
commit
107ec67105
1 changed files with 15 additions and 3 deletions
|
|
@ -2,11 +2,21 @@
|
||||||
#include <libowfat/buffer.h>
|
#include <libowfat/buffer.h>
|
||||||
#include <libowfat/errmsg.h>
|
#include <libowfat/errmsg.h>
|
||||||
#include <libowfat/str.h>
|
#include <libowfat/str.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#define AUTH_HEADER "Authorization: Bearer "
|
#define AUTH_HEADER "authorization: bearer "
|
||||||
#define AUTH_HEADER_LEN str_len(AUTH_HEADER)
|
#define AUTH_HEADER_LEN str_len(AUTH_HEADER)
|
||||||
|
|
||||||
// TODO make case insensitive according to https://www.rfc-editor.org/info/rfc7230/#section-3.2
|
static int startswithlower(stralloc *sa, char *prefix, size_t prefixlen)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
if (sa->len < prefixlen) return 0;
|
||||||
|
for (i=0;i<prefixlen;i++)
|
||||||
|
if (tolower(sa->s[i]) != prefix[i])
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int parse_token(buffer *b, stralloc *result)
|
int parse_token(buffer *b, stralloc *result)
|
||||||
{
|
{
|
||||||
stralloc line;
|
stralloc line;
|
||||||
|
|
@ -17,7 +27,9 @@ int parse_token(buffer *b, stralloc *result)
|
||||||
if (r==0) break;
|
if (r==0) break;
|
||||||
if (r<0) { carpsys("read line"); goto err; }
|
if (r<0) { carpsys("read line"); goto err; }
|
||||||
|
|
||||||
if (stralloc_starts(&line,AUTH_HEADER)) {
|
/* header field names are case-sensitive
|
||||||
|
* https://www.rfc-editor.org/info/rfc7230/#section-3.2 */
|
||||||
|
if (startswithlower(&line,AUTH_HEADER,AUTH_HEADER_LEN)) {
|
||||||
stralloc_chomp(&line);
|
stralloc_chomp(&line);
|
||||||
if (!stralloc_copyb(result, line.s+AUTH_HEADER_LEN,
|
if (!stralloc_copyb(result, line.s+AUTH_HEADER_LEN,
|
||||||
line.len-AUTH_HEADER_LEN)
|
line.len-AUTH_HEADER_LEN)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue