Browse Source

[core] HTTP_VERSION_2

master
Glenn Strauss 1 year ago
parent
commit
a8f8d5edc0
  1. 10
      src/http_kv.c
  2. 3
      src/http_kv.h
  3. 7
      src/mod_accesslog.c
  4. 3
      src/mod_magnet.c

10
src/http_kv.c

@ -19,6 +19,7 @@ typedef struct {
} keyvalue;
static const keyvalue http_versions[] = {
{ HTTP_VERSION_2, CONST_LEN_STR("HTTP/2.0") }, /* SERVER_PROTOCOL */
{ HTTP_VERSION_1_1, CONST_LEN_STR("HTTP/1.1") },
{ HTTP_VERSION_1_0, CONST_LEN_STR("HTTP/1.0") },
{ HTTP_VERSION_UNSET, 0, NULL }
@ -186,3 +187,12 @@ void http_method_append(buffer * const b, const http_method_t method) {
buffer_append_string_len(b, kv[i].value, kv[i].vlen);
}
}
void http_version_append(buffer * const b, const http_version_t version) {
const keyvalue * const kv = http_versions;
int i;
for (i = 0; kv[i].key != version && kv[i].vlen; ++i) ;
if (kv[i].vlen) {
buffer_append_string_len(b, kv[i].value, kv[i].vlen);
}
}

3
src/http_kv.h

@ -56,7 +56,7 @@ typedef enum {
HTTP_METHOD_VERSION_CONTROL /* [RFC3253], Section 3.5 */
} http_method_t;
typedef enum { HTTP_VERSION_UNSET = -1, HTTP_VERSION_1_0, HTTP_VERSION_1_1 } http_version_t;
typedef enum { HTTP_VERSION_UNSET = -1, HTTP_VERSION_1_0, HTTP_VERSION_1_1, HTTP_VERSION_2 } http_version_t;
const char *get_http_status_name(int i);
const char *get_http_version_name(int i);
@ -65,6 +65,7 @@ int get_http_version_key(const char *s, size_t slen);
http_method_t get_http_method_key(const char *s, size_t slen);
void http_status_append(buffer *b, int status);
void http_method_append(buffer *b, http_method_t method);
void http_version_append(buffer *b, http_version_t version);
#define http_method_get_or_head(method) ((method) <= HTTP_METHOD_HEAD)
#define http_method_get_head_post(method) ((method) <= HTTP_METHOD_POST)

7
src/mod_accesslog.c

@ -970,11 +970,11 @@ static int log_access_record (const request_st * const r, buffer * const b, form
break;
case FORMAT_REQUEST_LINE:
/*(attempt to reconstruct request line)*/
buffer_append_string(b, get_http_method_name(r->http_method));
http_method_append(b, r->http_method);
buffer_append_string_len(b, CONST_STR_LEN(" "));
accesslog_append_escaped(b, &r->target_orig);
buffer_append_string_len(b, CONST_STR_LEN(" "));
buffer_append_string(b, get_http_version_name(r->http_version));
http_version_append(b, r->http_version);
break;
case FORMAT_STATUS:
buffer_append_int(b, r->http_status);
@ -1046,8 +1046,7 @@ static int log_access_record (const request_st * const r, buffer * const b, form
}
break;
case FORMAT_REQUEST_PROTOCOL:
buffer_append_string_len(b,
r->http_version == HTTP_VERSION_1_1 ? "HTTP/1.1" : "HTTP/1.0", 8);
http_version_append(b, r->http_version);
break;
case FORMAT_REQUEST_METHOD:
http_method_append(b, r->http_method);

3
src/mod_magnet.c

@ -524,7 +524,8 @@ static buffer *magnet_env_get_buffer_by_id(request_st * const r, int id) {
}
case MAGNET_ENV_REQUEST_PROTOCOL:
dest = r->tmp_buf;
buffer_copy_string(dest, get_http_version_name(r->http_version));
buffer_clear(dest);
http_version_append(dest, r->http_version);
break;
case MAGNET_ENV_UNSET: break;

Loading…
Cancel
Save