http.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef __HTTP_H
  2. #define __HTTP_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at http://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. #ifndef CURL_DISABLE_HTTP
  25. extern const struct Curl_handler Curl_handler_http;
  26. #ifdef USE_SSL
  27. extern const struct Curl_handler Curl_handler_https;
  28. #endif
  29. bool Curl_compareheader(const char *headerline, /* line to check */
  30. const char *header, /* header keyword _with_ colon */
  31. const char *content); /* content string to find */
  32. char *Curl_checkheaders(struct SessionHandle *data, const char *thisheader);
  33. /* ------------------------------------------------------------------------- */
  34. /*
  35. * The add_buffer series of functions are used to build one large memory chunk
  36. * from repeated function invokes. Used so that the entire HTTP request can
  37. * be sent in one go.
  38. */
  39. struct Curl_send_buffer {
  40. char *buffer;
  41. size_t size_max;
  42. size_t size_used;
  43. };
  44. typedef struct Curl_send_buffer Curl_send_buffer;
  45. Curl_send_buffer *Curl_add_buffer_init(void);
  46. CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...);
  47. CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size);
  48. CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
  49. struct connectdata *conn,
  50. long *bytes_written,
  51. size_t included_body_bytes,
  52. int socketindex);
  53. CURLcode Curl_add_timecondition(struct SessionHandle *data,
  54. Curl_send_buffer *buf);
  55. CURLcode Curl_add_custom_headers(struct connectdata *conn,
  56. Curl_send_buffer *req_buffer);
  57. /* protocol-specific functions set up to be called by the main engine */
  58. CURLcode Curl_http(struct connectdata *conn, bool *done);
  59. CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature);
  60. CURLcode Curl_http_connect(struct connectdata *conn, bool *done);
  61. /* The following functions are defined in http_chunks.c */
  62. void Curl_httpchunk_init(struct connectdata *conn);
  63. CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap,
  64. ssize_t length, ssize_t *wrote);
  65. /* These functions are in http.c */
  66. void Curl_http_auth_stage(struct SessionHandle *data, int stage);
  67. CURLcode Curl_http_input_auth(struct connectdata *conn,
  68. int httpcode, const char *header);
  69. CURLcode Curl_http_auth_act(struct connectdata *conn);
  70. CURLcode Curl_http_perhapsrewind(struct connectdata *conn);
  71. /* If only the PICKNONE bit is set, there has been a round-trip and we
  72. selected to use no auth at all. Ie, we actively select no auth, as opposed
  73. to not having one selected. The other CURLAUTH_* defines are present in the
  74. public curl/curl.h header. */
  75. #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
  76. /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
  77. data get included in the initial data chunk sent to the server. If the
  78. data is larger than this, it will automatically get split up in multiple
  79. system calls.
  80. This value used to be fairly big (100K), but we must take into account that
  81. if the server rejects the POST due for authentication reasons, this data
  82. will always be uncondtionally sent and thus it may not be larger than can
  83. always be afforded to send twice.
  84. It must not be greater than 64K to work on VMS.
  85. */
  86. #ifndef MAX_INITIAL_POST_SIZE
  87. #define MAX_INITIAL_POST_SIZE (64*1024)
  88. #endif
  89. #ifndef TINY_INITIAL_POST_SIZE
  90. #define TINY_INITIAL_POST_SIZE 1024
  91. #endif
  92. #endif /* CURL_DISABLE_HTTP */
  93. /****************************************************************************
  94. * HTTP unique setup
  95. ***************************************************************************/
  96. struct HTTP {
  97. struct FormData *sendit;
  98. curl_off_t postsize; /* off_t to handle large file sizes */
  99. const char *postdata;
  100. const char *p_pragma; /* Pragma: string */
  101. const char *p_accept; /* Accept: string */
  102. curl_off_t readbytecount;
  103. curl_off_t writebytecount;
  104. /* For FORM posting */
  105. struct Form form;
  106. struct back {
  107. curl_read_callback fread_func; /* backup storage for fread pointer */
  108. void *fread_in; /* backup storage for fread_in pointer */
  109. const char *postdata;
  110. curl_off_t postsize;
  111. } backup;
  112. enum {
  113. HTTPSEND_NADA, /* init */
  114. HTTPSEND_REQUEST, /* sending a request */
  115. HTTPSEND_BODY, /* sending body */
  116. HTTPSEND_LAST /* never use this */
  117. } sending;
  118. void *send_buffer; /* used if the request couldn't be sent in one chunk,
  119. points to an allocated send_buffer struct */
  120. };
  121. CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
  122. struct connectdata *conn,
  123. ssize_t *nread,
  124. bool *stop_reading);
  125. /**
  126. * Curl_http_output_auth() setups the authentication headers for the
  127. * host/proxy and the correct authentication
  128. * method. conn->data->state.authdone is set to TRUE when authentication is
  129. * done.
  130. *
  131. * @param conn all information about the current connection
  132. * @param request pointer to the request keyword
  133. * @param path pointer to the requested path
  134. * @param proxytunnel boolean if this is the request setting up a "proxy
  135. * tunnel"
  136. *
  137. * @returns CURLcode
  138. */
  139. CURLcode
  140. Curl_http_output_auth(struct connectdata *conn,
  141. const char *request,
  142. const char *path,
  143. bool proxytunnel); /* TRUE if this is the request setting
  144. up the proxy tunnel */
  145. #endif