File
Blob: src/workerd/io/io-thread-context.h
| 1 | #pragma once |
| 2 | |
| 3 | #include <capnp/compat/http-over-capnp.h> |
| 4 | #include <kj/compat/http.h> |
| 5 | |
| 6 | namespace workerd { |
| 7 | |
| 8 | // Thread-level stuff needed to construct a IoContext. One of these is created for each |
| 9 | // request-handling thread. |
| 10 | class ThreadContext { |
| 11 | public: |
| 12 | struct HeaderIdBundle { |
| 13 | HeaderIdBundle(kj::HttpHeaderTable::Builder& builder); |
| 14 | |
| 15 | const kj::HttpHeaderTable& table; |
| 16 | |
| 17 | const kj::HttpHeaderId contentEncoding; |
| 18 | const kj::HttpHeaderId cfCacheStatus; // used by cache API implementation |
| 19 | const kj::HttpHeaderId cacheControl; |
| 20 | const kj::HttpHeaderId pragma; |
| 21 | const kj::HttpHeaderId cfCacheNamespace; // used by Cache binding implementation |
| 22 | const kj::HttpHeaderId range; |
| 23 | const kj::HttpHeaderId ifModifiedSince; |
| 24 | const kj::HttpHeaderId ifNoneMatch; |
| 25 | const kj::HttpHeaderId cfKvMetadata; // used by KV binding implementation |
| 26 | const kj::HttpHeaderId cfR2ErrorHeader; // used by R2 binding implementation |
| 27 | const kj::HttpHeaderId cfBlobMetadataSize; // used by R2 binding implementation |
| 28 | const kj::HttpHeaderId cfBlobRequest; // used by R2 binding implementation |
| 29 | const kj::HttpHeaderId authorization; // used by R2 binding implementation |
| 30 | const kj::HttpHeaderId cfQueuesErrorCode; // used by Queue binding implementation |
| 31 | const kj::HttpHeaderId cfQueuesErrorCause; // used by Queue binding implementation |
| 32 | const kj::HttpHeaderId secWebSocketProtocol; |
| 33 | const kj::HttpHeaderId userAgent; // used in tracing instrumentation |
| 34 | const kj::HttpHeaderId contentType; // used in tracing instrumentation |
| 35 | const kj::HttpHeaderId contentLength; // used in tracing instrumentation |
| 36 | const kj::HttpHeaderId accept; // used in tracing instrumentation |
| 37 | const kj::HttpHeaderId acceptEncoding; // used in tracing instrumentation |
| 38 | const kj::HttpHeaderId cfRay; // used in tracing instrumentation |
| 39 | const kj::HttpHeaderId origin; |
| 40 | }; |
| 41 | |
| 42 | ThreadContext(kj::Timer& timer, |
| 43 | kj::EntropySource& entropySource, |
| 44 | HeaderIdBundle headerIds, |
| 45 | capnp::HttpOverCapnpFactory& httpOverCapnpFactory, |
| 46 | capnp::ByteStreamFactory& byteStreamFactory); |
| 47 | |
| 48 | // This should only be used to construct TimerChannel. Everything else should use TimerChannel. |
| 49 | inline kj::Timer& getUnsafeTimer() const { |
| 50 | return timer; |
| 51 | } |
| 52 | inline kj::EntropySource& getEntropySource() const { |
| 53 | return entropySource; |
| 54 | } |
| 55 | inline const kj::HttpHeaderTable& getHeaderTable() const { |
| 56 | return headerIds.table; |
| 57 | } |
| 58 | inline const HeaderIdBundle& getHeaderIds() const { |
| 59 | return headerIds; |
| 60 | } |
| 61 | inline capnp::HttpOverCapnpFactory& getHttpOverCapnpFactory() const { |
| 62 | return httpOverCapnpFactory; |
| 63 | } |
| 64 | inline capnp::ByteStreamFactory& getByteStreamFactory() const { |
| 65 | return byteStreamFactory; |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | // NOTE: This timer only updates when entering the event loop! |
| 70 | kj::Timer& timer; |
| 71 | kj::EntropySource& entropySource; |
| 72 | HeaderIdBundle headerIds; |
| 73 | capnp::HttpOverCapnpFactory& httpOverCapnpFactory; |
| 74 | capnp::ByteStreamFactory& byteStreamFactory; |
| 75 | }; |
| 76 | |
| 77 | } // namespace workerd |