You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http_context.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. guint kp_cache_size_client;
  31. guint kp_cache_size_server;
  32. guint ssl_cache_size;
  33. gdouble keepalive_interval;
  34. gdouble client_key_rotate_time;
  35. const gchar *user_agent;
  36. const gchar *http_proxy;
  37. const gchar *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 (
  67. struct rspamd_http_context *ctx, const rspamd_inet_addr_t *addr,
  68. const gchar *host);
  69. /**
  70. * Prepares keepalive key for a connection by creating a new entry or by reusing existent
  71. * Bear in mind, that keepalive pool has currently no cleanup methods!
  72. * @param ctx
  73. * @param conn
  74. * @param addr
  75. * @param host
  76. */
  77. void rspamd_http_context_prepare_keepalive (struct rspamd_http_context *ctx,
  78. struct rspamd_http_connection *conn,
  79. const rspamd_inet_addr_t *addr,
  80. const gchar *host);
  81. /**
  82. * Pushes a connection to keepalive pool after client request is finished,
  83. * keepalive key *must* be prepared before using of this function
  84. * @param ctx
  85. * @param conn
  86. * @param msg
  87. */
  88. void rspamd_http_context_push_keepalive (struct rspamd_http_context *ctx,
  89. struct rspamd_http_connection *conn,
  90. struct rspamd_http_message *msg,
  91. struct ev_loop *ev_base);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif