Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

http_context.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*-
  2. * Copyright 2019 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef RSPAMD_HTTP_CONTEXT_H
  17. #define RSPAMD_HTTP_CONTEXT_H
  18. #include "config.h"
  19. #include "ucl.h"
  20. #include "addr.h"
  21. #include "contrib/libev/ev.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. struct rspamd_http_context;
  26. struct rspamd_config;
  27. struct rspamd_http_message;
  28. struct upstream_ctx;
  29. struct rspamd_http_context_cfg {
  30. unsigned int kp_cache_size_client;
  31. unsigned int kp_cache_size_server;
  32. unsigned int ssl_cache_size;
  33. double keepalive_interval;
  34. double client_key_rotate_time;
  35. const char *user_agent;
  36. const char *http_proxy;
  37. const char *server_hdr;
  38. };
  39. /**
  40. * Creates and configures new HTTP context
  41. * @param root_conf configuration object
  42. * @param ev_base event base
  43. * @return new context used for both client and server HTTP connections
  44. */
  45. struct rspamd_http_context *rspamd_http_context_create(struct rspamd_config *cfg,
  46. struct ev_loop *ev_base,
  47. struct upstream_ctx *ctx);
  48. struct rspamd_http_context *rspamd_http_context_create_config(
  49. struct rspamd_http_context_cfg *cfg,
  50. struct ev_loop *ev_base,
  51. struct upstream_ctx *ctx);
  52. /**
  53. * Destroys context
  54. * @param ctx
  55. */
  56. void rspamd_http_context_free(struct rspamd_http_context *ctx);
  57. struct rspamd_http_context *rspamd_http_context_default(void);
  58. /**
  59. * Returns preserved keepalive connection if it's available.
  60. * Refcount is transferred to caller!
  61. * @param ctx
  62. * @param addr
  63. * @param host
  64. * @return
  65. */
  66. struct rspamd_http_connection *rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx,
  67. const rspamd_inet_addr_t *addr,
  68. const char *host,
  69. bool is_ssl);
  70. /**
  71. * Checks if there is a valid keepalive connection
  72. * @param ctx
  73. * @param addr
  74. * @param host
  75. * @param is_ssl
  76. * @return
  77. */
  78. const rspamd_inet_addr_t *rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx,
  79. const char *host,
  80. unsigned port,
  81. bool is_ssl);
  82. /**
  83. * Prepares keepalive key for a connection by creating a new entry or by reusing existent
  84. * Bear in mind, that keepalive pool has currently no cleanup methods!
  85. * @param ctx
  86. * @param conn
  87. * @param addr
  88. * @param host
  89. */
  90. void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx, struct rspamd_http_connection *conn,
  91. const rspamd_inet_addr_t *addr, const char *host, bool is_ssl);
  92. /**
  93. * Pushes a connection to keepalive pool after client request is finished,
  94. * keepalive key *must* be prepared before using of this function
  95. * @param ctx
  96. * @param conn
  97. * @param msg
  98. */
  99. void rspamd_http_context_push_keepalive(struct rspamd_http_context *ctx,
  100. struct rspamd_http_connection *conn,
  101. struct rspamd_http_message *msg,
  102. struct ev_loop *ev_base);
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif