Skip to content

Commit 2da4a4e

Browse files
committed
allow HTTP body reader position detection
1 parent ed9cab4 commit 2da4a4e

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

fio-stl.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -41575,9 +41575,16 @@ SFUNC size_t fio_http_request_header_each(fio_http_s *,
4157541575
/** Gets the body (payload) length associated with the HTTP handle. */
4157641576
SFUNC size_t fio_http_body_length(fio_http_s *);
4157741577

41578-
/** Adjusts the body's reading position. Negative values start at the end. */
41578+
/**
41579+
* Adjusts the body's reading position. Negative values start at the end.
41580+
*
41581+
* If `pos == SSIZE_MAX`, returns `fio_http_body_pos`.
41582+
*/
4157941583
SFUNC size_t fio_http_body_seek(fio_http_s *, ssize_t pos);
4158041584

41585+
/** Returns the body's reading position. */
41586+
SFUNC size_t fio_http_body_pos(fio_http_s *h);
41587+
4158141588
/** Reads up to `length` of data from the body, returns nothing on EOF. */
4158241589
SFUNC fio_str_info_s fio_http_body_read(fio_http_s *, size_t length);
4158341590

@@ -43579,6 +43586,8 @@ SFUNC int fio_http_body_fd(fio_http_s *h) { return h->body.fd; }
4357943586

4358043587
/** Adjusts the body's reading position. Negative values start at the end. */
4358143588
SFUNC size_t fio_http_body_seek(fio_http_s *h, ssize_t pos) {
43589+
if (pos == SSIZE_MAX)
43590+
pos = h->body.pos;
4358243591
if (pos < 0) {
4358343592
pos += h->body.len;
4358443593
if (pos < 0)
@@ -43590,6 +43599,9 @@ SFUNC size_t fio_http_body_seek(fio_http_s *h, ssize_t pos) {
4359043599
return pos;
4359143600
}
4359243601

43602+
/** Returns the body's reading position. */
43603+
SFUNC size_t fio_http_body_pos(fio_http_s *h) { return h->body.pos; }
43604+
4359343605
/** Reads up to `length` of data from the body, returns nothing on EOF. */
4359443606
SFUNC fio_str_info_s fio_http_body_read(fio_http_s *h, size_t length) {
4359543607
fio_str_info_s r = {0};

fio-stl.md

+8
Original file line numberDiff line numberDiff line change
@@ -11968,6 +11968,13 @@ size_t fio_http_body_length(fio_http_s *);
1196811968

1196911969
Gets the body (payload) length associated with the HTTP handle.
1197011970

11971+
#### `fio_http_body_pos`
11972+
11973+
```c
11974+
size_t fio_http_body_pos(fio_http_s *h);
11975+
```
11976+
11977+
Returns the body's reading position.
1197111978

1197211979
#### `fio_http_body_seek`
1197311980
```c
@@ -11976,6 +11983,7 @@ size_t fio_http_body_seek(fio_http_s *, ssize_t pos);
1197611983

1197711984
Adjusts the body's reading position. Negative values start at the end.
1197811985

11986+
If `pos == SSIZE_MAX`, returns `fio_http_body_pos`.
1197911987

1198011988
#### `fio_http_body_read`
1198111989
```c

fio-stl/431 http handle.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,16 @@ SFUNC size_t fio_http_request_header_each(fio_http_s *,
261261
/** Gets the body (payload) length associated with the HTTP handle. */
262262
SFUNC size_t fio_http_body_length(fio_http_s *);
263263

264-
/** Adjusts the body's reading position. Negative values start at the end. */
264+
/**
265+
* Adjusts the body's reading position. Negative values start at the end.
266+
*
267+
* If `pos == SSIZE_MAX`, returns `fio_http_body_pos`.
268+
*/
265269
SFUNC size_t fio_http_body_seek(fio_http_s *, ssize_t pos);
266270

271+
/** Returns the body's reading position. */
272+
SFUNC size_t fio_http_body_pos(fio_http_s *h);
273+
267274
/** Reads up to `length` of data from the body, returns nothing on EOF. */
268275
SFUNC fio_str_info_s fio_http_body_read(fio_http_s *, size_t length);
269276

@@ -2265,6 +2272,8 @@ SFUNC int fio_http_body_fd(fio_http_s *h) { return h->body.fd; }
22652272

22662273
/** Adjusts the body's reading position. Negative values start at the end. */
22672274
SFUNC size_t fio_http_body_seek(fio_http_s *h, ssize_t pos) {
2275+
if (pos == SSIZE_MAX)
2276+
pos = h->body.pos;
22682277
if (pos < 0) {
22692278
pos += h->body.len;
22702279
if (pos < 0)
@@ -2276,6 +2285,9 @@ SFUNC size_t fio_http_body_seek(fio_http_s *h, ssize_t pos) {
22762285
return pos;
22772286
}
22782287

2288+
/** Returns the body's reading position. */
2289+
SFUNC size_t fio_http_body_pos(fio_http_s *h) { return h->body.pos; }
2290+
22792291
/** Reads up to `length` of data from the body, returns nothing on EOF. */
22802292
SFUNC fio_str_info_s fio_http_body_read(fio_http_s *h, size_t length) {
22812293
fio_str_info_s r = {0};

fio-stl/439 http.md

+8
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,13 @@ size_t fio_http_body_length(fio_http_s *);
491491
492492
Gets the body (payload) length associated with the HTTP handle.
493493
494+
#### `fio_http_body_pos`
495+
496+
```c
497+
size_t fio_http_body_pos(fio_http_s *h);
498+
```
499+
500+
Returns the body's reading position.
494501

495502
#### `fio_http_body_seek`
496503
```c
@@ -499,6 +506,7 @@ size_t fio_http_body_seek(fio_http_s *, ssize_t pos);
499506
500507
Adjusts the body's reading position. Negative values start at the end.
501508
509+
If `pos == SSIZE_MAX`, returns `fio_http_body_pos`.
502510
503511
#### `fio_http_body_read`
504512
```c

0 commit comments

Comments
 (0)