httptest.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef _HTTPTEST_HPP__
  14. #define _HTTPTEST_HPP__
  15. #include "jliball.hpp"
  16. #include "securesocket.hpp"
  17. extern int httptest_tracelevel;
  18. class HttpStat
  19. {
  20. public:
  21. int msecs;
  22. int slowest;
  23. int fastest;
  24. __int64 totalreqlen;
  25. __int64 totalresplen;
  26. int numrequests;
  27. HttpStat()
  28. {
  29. msecs = 0;
  30. slowest = 0;
  31. fastest = 2147483647;
  32. totalreqlen = 0;
  33. totalresplen = 0;
  34. numrequests = 0;
  35. }
  36. void printStat(FILE* ofile)
  37. {
  38. fprintf(ofile, "Total hits: %d\n", numrequests);
  39. fprintf(ofile, "Time taken(millisecond): %d\n", msecs);
  40. fprintf(ofile, "Hits per second: %3.1f\n", numrequests/(msecs*0.001));
  41. fprintf(ofile, "Total data sent: %" I64F "d\n", totalreqlen);
  42. fprintf(ofile, "Total data received: %" I64F "d\n", totalresplen);
  43. __int64 totallen = totalreqlen + totalresplen;
  44. fprintf(ofile, "Total data transferred: %" I64F "d\n", totallen);
  45. fprintf(ofile, "Data transferred per second: %5.1f\n", totallen/(msecs*0.001));
  46. fprintf(ofile, "Slowest round trip(millisecond): %d\n", slowest);
  47. fprintf(ofile, "Fastest round trip(millisecond): %d\n", fastest);
  48. }
  49. };
  50. class HttpClient
  51. {
  52. private:
  53. int m_threads;
  54. int m_times;
  55. StringBuffer m_host;
  56. int m_port;
  57. FILE* m_ofile;
  58. bool m_use_ssl;
  59. Owned<ISecureSocketContext> m_ssctx;
  60. int m_delay;
  61. HttpStat m_stat;
  62. public:
  63. HttpClient(int threads, int times, FILE* ofile);
  64. HttpClient(int threads, int times, const char* host, int port, FILE* ofile, bool use_ssl, IPropertyTree* sslconfig);
  65. int sendRequest(StringBuffer& req);
  66. int sendRequest(int times, HttpStat& stat, StringBuffer& req);
  67. int sendRequest(const char* infile);
  68. int getUrl(const char* url);
  69. int sendSoapRequest(const char* url, const char* soapaction, const char* infile);
  70. void setDelay(int secs);
  71. HttpStat& getStat() {return m_stat;}
  72. };
  73. class HttpServer
  74. {
  75. int m_port;
  76. StringBuffer m_ifname;
  77. StringBuffer m_response;
  78. FILE* m_ofile;
  79. bool m_use_ssl;
  80. Owned<ISecureSocketContext> m_ssctx;
  81. int m_recvDelay;
  82. int m_sendDelay;
  83. int m_closeDelay;
  84. void handleOneRequest(ISocket* client);
  85. public:
  86. HttpServer(int port, const char* in, FILE* ofile, bool use_ssl, IPropertyTree* sslconfig);
  87. void setDelays(int recvDelay, int sendDelay, int closeDelay)
  88. {
  89. m_recvDelay = recvDelay;
  90. m_sendDelay = sendDelay;
  91. m_closeDelay = closeDelay;
  92. }
  93. int start();
  94. };
  95. class COneServerHttpProxyThread
  96. {
  97. private:
  98. Owned<ISocket> m_client;
  99. StringBuffer m_host;
  100. int m_port;
  101. FILE* m_ofile;
  102. bool m_use_ssl;
  103. ISecureSocketContext* m_ssctx;
  104. public:
  105. COneServerHttpProxyThread(ISocket* client, const char* host, int port, FILE* ofile, bool use_ssl, ISecureSocketContext* ssctx);
  106. virtual int start();
  107. };
  108. class CHttpProxyThread : public Thread
  109. {
  110. private:
  111. Owned<ISocket> m_client;
  112. FILE* m_ofile;
  113. Owned<ISocket> m_remotesocket;
  114. public:
  115. CHttpProxyThread(ISocket* client, FILE* ofile);
  116. virtual void start();
  117. virtual int run();
  118. int readline(ISocket* socket, char* buf, int bufsize, bool& socketclosed);
  119. };
  120. class HttpProxy
  121. {
  122. private:
  123. int m_localport;
  124. StringBuffer m_host;
  125. int m_port;
  126. FILE* m_ofile;
  127. bool m_use_ssl;
  128. Owned<ISecureSocketContext> m_ssctx;
  129. public:
  130. HttpProxy(int localport, const char* host, int port, FILE* ofile, bool use_ssl, IPropertyTree* sslconfig);
  131. int start();
  132. };
  133. void SplitURL(const char* url, StringBuffer& protocol,StringBuffer& UserName,StringBuffer& Password,StringBuffer& host, StringBuffer& port, StringBuffer& path);
  134. #endif