aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/transport
diff options
context:
space:
mode:
authorGravatar Hope Casey-Allen <hcaseyal@google.com>2018-08-28 20:22:15 -0700
committerGravatar Hope Casey-Allen <hcaseyal@google.com>2018-08-28 20:37:18 -0700
commit73d0cd4d2d16e59a5b2ec21614b1511822e2039a (patch)
tree567da679b28fc263f5dd77e102af5d0e0f1f19a0 /src/core/lib/transport
parentee65a5eaee45a765d1d4176a797bb8288faeb180 (diff)
Add ability to use static hpack table on the encode path
Diffstat (limited to 'src/core/lib/transport')
-rw-r--r--src/core/lib/transport/metadata.h190
-rw-r--r--src/core/lib/transport/metadata_batch.cc27
-rw-r--r--src/core/lib/transport/metadata_batch.h30
3 files changed, 243 insertions, 4 deletions
diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h
index 78df4bc3a3..eeb09aff97 100644
--- a/src/core/lib/transport/metadata.h
+++ b/src/core/lib/transport/metadata.h
@@ -162,4 +162,194 @@ void grpc_mdelem_unref(grpc_mdelem md);
void grpc_mdctx_global_init(void);
void grpc_mdctx_global_shutdown();
+#define MIN_STATIC_HPACK_TABLE_IDX 1
+#define MAX_STATIC_HPACK_TABLE_IDX 61
+
+/* Static hpack table metadata indices */
+
+/* {:authority, ""} */
+#define GRPC_MDELEM_AUTHORITY_EMPTY_INDEX 1
+
+/* {":method", "GET"} */
+#define GRPC_MDELEM_METHOD_GET_INDEX 2
+
+/* {":method", "POST"} */
+#define GRPC_MDELEM_METHOD_POST_INDEX 3
+
+/* {":path", "/"} */
+#define GRPC_MDELEM_PATH_SLASH_INDEX 4
+
+/* {":path", "/index.html"} */
+#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML_INDEX 5
+
+/* {":scheme", "http"} */
+#define GRPC_MDELEM_SCHEME_HTTP_INDEX 6
+
+/* {":scheme", "https"} */
+#define GRPC_MDELEM_SCHEME_HTTPS_INDEX 7
+
+/* {":status", "200"} */
+#define GRPC_MDELEM_STATUS_200_INDEX 8
+
+/* {":status", "204"} */
+#define GRPC_MDELEM_STATUS_204_INDEX 9
+
+/* {":status", "206"} */
+#define GRPC_MDELEM_STATUS_206_INDEX 10
+
+/* {":status", "304"} */
+#define GRPC_MDELEM_STATUS_304_INDEX 11
+
+/* {":status", "400"} */
+#define GRPC_MDELEM_STATUS_400_INDEX 12
+
+/* {":status", "404"} */
+#define GRPC_MDELEM_STATUS_404_INDEX 13
+
+/* {":status", "500"} */
+#define GRPC_MDELEM_STATUS_500_INDEX 14
+
+/* {"accept-charset", ""} */
+#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY_INDEX 15
+
+/* {"accept-encoding", "gzip, deflate"} */
+#define GRPC_MDELEM_ACCEPT_ENCODING_GZIP_DEFLATE_INDEX 16
+
+/* {"accept-language", ""} */
+#define GRPC_MDELEM_MDELEM_ACCEPT_LANGUAGE_EMPTY_INDEX 17
+
+/* {"accept-ranges", ""} */
+#define GRPC_MDELEM_MDELEM_ACCEPT_RANGES_EMPTY_INDEX 18
+
+/* {"accept", ""} */
+#define GRPC_MDELEM_ACCEPT_EMPTY_INDEX 19
+
+/* {"access-control-allow-origin", ""} */
+#define GRPC_MDELEM_ACCESS_CONTROL_ALLOW_ORIGIN_EMPTY_INDEX 20
+
+/* {"age", ""} */
+#define GRPC_MDELEM_AGE_EMPTY_INDEX 21
+
+/* {"allow", ""} */
+#define GRPC_MDELEM_ALLOW_EMPTY_INDEX 22
+
+/* {"authorization", ""} */
+#define GRPC_MDELEM_AUTHORIZATION_EMPTY_INDEX 23
+
+/* {"cache-control", ""} */
+#define GRPC_MDELEM_CACHE_CONTROL_EMPTY_INDEX 24
+
+/* {"content-disposition", ""} */
+#define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY_INDEX 25
+
+/* {"content-encoding", ""} */
+#define GRPC_MDELEM_CONTENT_ENCODING_EMPTY_INDEX 26
+
+/* {"content-language", ""} */
+#define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY_INDEX 27
+
+/* {"content-length", ""} */
+#define GRPC_MDELEM_CONTENT_LENGTH_EMPTY_INDEX 28
+
+/* {"content-location", ""} */
+#define GRPC_MDELEM_CONTENT_LOCATION_EMPTY_INDEX 29
+
+/* {"content-range", ""} */
+#define GRPC_MDELEM_CONTENT_RANGE_EMPTY_INDEX 30
+
+/* {"content-type", ""} */
+#define GRPC_MDELEM_CONTENT_TYPE_EMPTY_INDEX 31
+
+/* {"cookie", ""} */
+#define GRPC_MDELEM_COOKIE_EMPTY_INDEX 32
+
+/* {"date", ""} */
+#define GRPC_MDELEM_DATE_EMPTY_INDEX 33
+
+/* {"etag", ""} */
+#define GRPC_MDELEM_ETAG_EMPTY_INDEX 34
+
+/* {"expect", ""} */
+#define GRPC_MDELEM_EXPECT_EMPTY_INDEX 35
+
+/* {"expires", ""} */
+#define GRPC_MDELEM_EXPIRES_EMPTY_INDEX 36
+
+/* {"from", ""} */
+#define GRPC_MDELEM_FROM_EMPTY_INDEX 37
+
+/* {"host", ""} */
+#define GRPC_MDELEM_HOST_EMPTY_INDEX 38
+
+/* {"if-match", ""} */
+#define GRPC_MDELEM_IF_MATCH_EMPTY_INDEX 39
+
+/* {"if-modified-since", ""} */
+#define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY_INDEX 40
+
+/* {"if-none-match", ""} */
+#define GRPC_MDELEM_IF_NONE_MATCH_EMPTY_INDEX 41
+
+/* {"if-range", ""} */
+#define GRPC_MDELEM_IF_RANGE_EMPTY_INDEX 42
+
+/* {"if-unmodified-since", ""} */
+#define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY_INDEX 43
+
+/* {"last-modified", ""} */
+#define GRPC_MDELEM_LAST_MODIFIED_EMPTY_INDEX 44
+
+/* {"link", ""} */
+#define GRPC_MDELEM_LINK_EMPTY_INDEX 45
+
+/* {"location", ""} */
+#define GRPC_MDELEM_LOCATION_EMPTY_INDEX 46
+
+/* {"max-forwards", ""} */
+#define GRPC_MDELEM_MAX_FORWARDS_EMPTY_INDEX 47
+
+/* {"proxy-authenticate", ""} */
+#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY_INDEX 48
+
+/* {"proxy-authorization", ""} */
+#define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY_INDEX 49
+
+/* {"range", ""} */
+#define GRPC_MDELEM_RANGE_EMPTY_INDEX 50
+
+/* {"referer", ""} */
+#define GRPC_MDELEM_REFERER_EMPTY_INDEX 51
+
+/* {"refresh", ""} */
+#define GRPC_MDELEM_REFRESH_EMPTY_INDEX 52
+
+/* {"retry-after", ""} */
+#define GRPC_MDELEM_RETRY_AFTER_EMPTY_INDEX 53
+
+/* {"server", ""} */
+#define GRPC_MDELEM_SERVER_EMPTY_INDEX 54
+
+/* {"set-cookie", ""} */
+#define GRPC_MDELEM_SET_COOKIE_EMPTY_INDEX 55 * /
+
+/* {"strict-transport-security", ""} */
+#define GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY_INDEX 56
+
+/* {"transfer-encoding", ""} */
+#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY_INDEX 57
+
+/* {"user-agent", ""} */
+#define GRPC_MDELEM_USER_AGENT_EMPTY_INDEX 58
+
+/* {"vary", ""} */
+#define GRPC_MDELEM_VARY_EMPTY_INDEX 59
+
+/* {"via", ""} */
+#define GRPC_MDELEM_VIA_EMPTY_INDEX 60
+
+/* {"www-authenticate", ""} */
+#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY_INDEX 61
+
+/* Forward declarations */
+typedef struct grpc_mdelem grpc_mdelem;
#endif /* GRPC_CORE_LIB_TRANSPORT_METADATA_H */
diff --git a/src/core/lib/transport/metadata_batch.cc b/src/core/lib/transport/metadata_batch.cc
index 49740fcd1e..6cad7c9028 100644
--- a/src/core/lib/transport/metadata_batch.cc
+++ b/src/core/lib/transport/metadata_batch.cc
@@ -126,6 +126,11 @@ static void maybe_unlink_callout(grpc_metadata_batch* batch,
batch->idx.array[idx] = nullptr;
}
+bool is_valid_mdelem_index(int64_t index) {
+ return index >= MIN_STATIC_HPACK_TABLE_IDX &&
+ index <= MAX_STATIC_HPACK_TABLE_IDX;
+}
+
grpc_error* grpc_metadata_batch_add_head(grpc_metadata_batch* batch,
grpc_linked_mdelem* storage,
grpc_mdelem elem_to_add) {
@@ -134,9 +139,18 @@ grpc_error* grpc_metadata_batch_add_head(grpc_metadata_batch* batch,
return grpc_metadata_batch_link_head(batch, storage);
}
+grpc_error* grpc_metadata_batch_add_head_index(grpc_metadata_batch* batch,
+ grpc_linked_mdelem* storage,
+ int64_t index_to_add) {
+ GPR_ASSERT(is_valid_mdelem_index(index_to_add));
+ storage->md_index = index_to_add;
+ return grpc_metadata_batch_link_head(batch, storage);
+}
+
static void link_head(grpc_mdelem_list* list, grpc_linked_mdelem* storage) {
assert_valid_list(list);
- GPR_ASSERT(!GRPC_MDISNULL(storage->md));
+ GPR_ASSERT(is_valid_mdelem_index(storage->md_index) ||
+ !GRPC_MDISNULL(storage->md));
storage->prev = nullptr;
storage->next = list->head;
if (list->head != nullptr) {
@@ -170,9 +184,18 @@ grpc_error* grpc_metadata_batch_add_tail(grpc_metadata_batch* batch,
return grpc_metadata_batch_link_tail(batch, storage);
}
+grpc_error* grpc_metadata_batch_add_tail_index(grpc_metadata_batch* batch,
+ grpc_linked_mdelem* storage,
+ int64_t index_to_add) {
+ GPR_ASSERT(is_valid_mdelem_index(index_to_add));
+ storage->md_index = index_to_add;
+ return grpc_metadata_batch_link_tail(batch, storage);
+}
+
static void link_tail(grpc_mdelem_list* list, grpc_linked_mdelem* storage) {
assert_valid_list(list);
- GPR_ASSERT(!GRPC_MDISNULL(storage->md));
+ GPR_ASSERT(is_valid_mdelem_index(storage->md_index) ||
+ !GRPC_MDISNULL(storage->md));
storage->prev = list->tail;
storage->next = nullptr;
storage->reserved = nullptr;
diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h
index 7068750b6f..f1c199489f 100644
--- a/src/core/lib/transport/metadata_batch.h
+++ b/src/core/lib/transport/metadata_batch.h
@@ -30,8 +30,16 @@
#include "src/core/lib/transport/metadata.h"
#include "src/core/lib/transport/static_metadata.h"
+/** Each grpc_linked_mdelem refers to a particular metadata element by either:
+ 1) grpc_mdelem md
+ 2) int64_t md_index
+ md_index is an optional optimization. It can only be used for metadata in
+ the hpack static table and is equivalent to the metadata's index in the
+ table. If a metadata elem is not contained in the hpack static table, then
+ md must be used instead. */
typedef struct grpc_linked_mdelem {
- grpc_mdelem md;
+ int64_t md_index; // If -1, not used. Else, use this field instead of md.
+ grpc_mdelem md; // If md_index is 0, use this field instead of md_index.
struct grpc_linked_mdelem* next;
struct grpc_linked_mdelem* prev;
void* reserved;
@@ -50,7 +58,7 @@ typedef struct grpc_metadata_batch {
grpc_metadata_batch_callouts idx;
/** Used to calculate grpc-timeout at the point of sending,
or GRPC_MILLIS_INF_FUTURE if this batch does not need to send a
- grpc-timeout */
+ grpc-timeout. */
grpc_millis deadline;
} grpc_metadata_batch;
@@ -82,6 +90,7 @@ void grpc_metadata_batch_set_value(grpc_linked_mdelem* storage,
grpc_error* grpc_metadata_batch_link_head(grpc_metadata_batch* batch,
grpc_linked_mdelem* storage)
GRPC_MUST_USE_RESULT;
+
/** Add \a storage to the end of \a batch. storage->md is
assumed to be valid.
\a storage is owned by the caller and must survive for the
@@ -100,6 +109,14 @@ grpc_error* grpc_metadata_batch_link_tail(grpc_metadata_batch* batch,
grpc_error* grpc_metadata_batch_add_head(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT;
+
+/** Identical to grpc_metadata_batch_add_head, except takes the index of the
+ metadata element to add instead of a grpc_mdelem object. The index must
+ be a valid static hpack table index */
+grpc_error* grpc_metadata_batch_add_head_index(
+ grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
+ int64_t index_to_add) GRPC_MUST_USE_RESULT;
+
/** Add \a elem_to_add as the last element in \a batch, using
\a storage as backing storage for the linked list element.
\a storage is owned by the caller and must survive for the
@@ -110,8 +127,17 @@ grpc_error* grpc_metadata_batch_add_tail(
grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT;
+/** Identical to grpc_metadata_batch_add_tail, except takes the index of the
+ metadata element to add instead of a grpc_mdelem object. The index must
+ be a valid static hpack table index */
+grpc_error* grpc_metadata_batch_add_head_index(
+ grpc_metadata_batch* batch, grpc_linked_mdelem* storage,
+ int64_t index_to_add) GRPC_MUST_USE_RESULT;
+
grpc_error* grpc_attach_md_to_error(grpc_error* src, grpc_mdelem md);
+bool is_valid_mdelem_index(int64_t index);
+
typedef struct {
grpc_error* error;
grpc_mdelem md;