File tree 5 files changed +42
-20
lines changed
5 files changed +42
-20
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ example/simplecli
7
7
example /simplesvr
8
8
example /benchmark
9
9
example /redirect
10
- example /sse
10
+ example /sse *
11
11
example /upload
12
12
example /* .pem
13
13
test /test
Original file line number Diff line number Diff line change @@ -243,7 +243,9 @@ svr.set_payload_max_length(1024 * 1024 * 512); // 512MB
243
243
244
244
### Server-Sent Events
245
245
246
- Please check [ here] ( https://github.com/yhirose/cpp-httplib/blob/master/example/sse.cc ) .
246
+ [ Server example] ( https://github.com/yhirose/cpp-httplib/blob/master/example/ssesvr.cc )
247
+
248
+ [ Client example] ( https://github.com/yhirose/cpp-httplib/blob/master/example/ssecli.cc )
247
249
248
250
### Default thread pool support
249
251
@@ -306,20 +308,6 @@ httplib::Headers headers = {
306
308
auto res = cli.Get(" /hi" , headers);
307
309
```
308
310
309
- ### GET with Content Receiver
310
-
311
- ``` c++
312
- std::string body;
313
-
314
- auto res = cli.Get(" /large-data" ,
315
- [&](const char *data, size_t data_length) {
316
- body.append(data, data_length);
317
- return true;
318
- });
319
-
320
- assert (res->body.empty());
321
- ```
322
-
323
311
### POST
324
312
325
313
``` c++
@@ -390,6 +378,16 @@ cli.set_write_timeout(5, 0); // 5 seconds
390
378
391
379
### Receive content with Content receiver
392
380
381
+ ``` c++
382
+ std::string body;
383
+
384
+ auto res = cli.Get(" /large-data" ,
385
+ [&](const char *data, size_t data_length) {
386
+ body.append(data, data_length);
387
+ return true;
388
+ });
389
+ ```
390
+
393
391
```cpp
394
392
std::string body;
395
393
auto res = cli.Get(
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ OPENSSL_DIR = /usr/local/opt/openssl
5
5
OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR ) /include -L$(OPENSSL_DIR ) /lib -lssl -lcrypto
6
6
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
7
7
8
- all : server client hello simplecli simplesvr upload redirect sse benchmark
8
+ all : server client hello simplecli simplesvr upload redirect ssesvr ssecli benchmark
9
9
10
10
server : server.cc ../httplib.h Makefile
11
11
$(CXX ) -o server $(CXXFLAGS ) server.cc $(OPENSSL_SUPPORT ) $(ZLIB_SUPPORT )
@@ -28,8 +28,11 @@ upload : upload.cc ../httplib.h Makefile
28
28
redirect : redirect.cc ../httplib.h Makefile
29
29
$(CXX ) -o redirect $(CXXFLAGS ) redirect.cc $(OPENSSL_SUPPORT ) $(ZLIB_SUPPORT )
30
30
31
- sse : sse.cc ../httplib.h Makefile
32
- $(CXX ) -o sse $(CXXFLAGS ) sse.cc $(OPENSSL_SUPPORT ) $(ZLIB_SUPPORT )
31
+ ssesvr : ssesvr.cc ../httplib.h Makefile
32
+ $(CXX ) -o ssesvr $(CXXFLAGS ) ssesvr.cc $(OPENSSL_SUPPORT ) $(ZLIB_SUPPORT )
33
+
34
+ ssecli : ssecli.cc ../httplib.h Makefile
35
+ $(CXX ) -o ssecli $(CXXFLAGS ) ssecli.cc $(OPENSSL_SUPPORT ) $(ZLIB_SUPPORT )
33
36
34
37
benchmark : benchmark.cc ../httplib.h Makefile
35
38
$(CXX ) -o benchmark $(CXXFLAGS ) benchmark.cc $(OPENSSL_SUPPORT ) $(ZLIB_SUPPORT )
39
42
openssl req -new -key key.pem | openssl x509 -days 3650 -req -signkey key.pem > cert.pem
40
43
41
44
clean :
42
- rm server client hello simplecli simplesvr upload redirect sse benchmark * .pem
45
+ rm server client hello simplecli simplesvr upload redirect ssesvr sselci benchmark * .pem
Original file line number Diff line number Diff line change
1
+ //
2
+ // ssecli.cc
3
+ //
4
+ // Copyright (c) 2019 Yuji Hirose. All rights reserved.
5
+ // MIT License
6
+ //
7
+
8
+ #include < httplib.h>
9
+ #include < iostream>
10
+
11
+ using namespace std ;
12
+
13
+ int main (void ) {
14
+ httplib::Client2 (" http://localhost:1234" )
15
+ .Get (" /event1" , [&](const char *data, size_t data_length) {
16
+ std::cout << string (data, data_length);
17
+ return true ;
18
+ });
19
+
20
+ return 0 ;
21
+ }
File renamed without changes.
You can’t perform that action at this time.
0 commit comments