Comments (4)
Got it working in a test by clearing the position- and length variables of httpc_t
before an operation.
diff --git a/httpc.c b/httpc.c
index bd0fcf9..c3b5506 100644
--- a/httpc.c
+++ b/httpc.c
@@ -1355,6 +1355,11 @@ static int httpc_op_heap(httpc_options_t *a, const char *url, int op, httpc_call
h->rcv_param = rcv_param;
h->snd_param = snd_param;
}
+
+ h->position = 0;
+ h->length = 0;
+ h->max = 0;
+ h->length_set = 0;
const int r = httpc_state_machine(h, url, op);
if (r != HTTPC_YIELD && r != HTTPC_REUSE)
a->state = NULL; /* make sure this is not reused */
Not sure if it's the correct approach though.
Edit: I think the following will need the same re-assignment treatment, or a HEAD
followed by a GET
will fail since h
will be reused with empty callbacks:
h->rcv = rcv;
h->snd = snd;
h->rcv_param = rcv_param;
h->snd_param = snd_param;
from httpc.
I'll try to have a look at this once (if) I have time over the weekend, I should probably add some more unit tests to cover these new additions as well.
from httpc.
I've found some more fields that would have to be moved.
diff --git a/httpc.c b/httpc.c
index c7e6b79..cb103c9 100644
--- a/httpc.c
+++ b/httpc.c
@@ -1357,12 +1357,18 @@ static int httpc_op_heap(httpc_options_t *a, const char *url, int op, httpc_call
return HTTPC_ERROR;
memset(h, 0, sizeof *h);
a->state = h;
- h->os = a;
- h->rcv = rcv;
- h->snd = snd;
- h->rcv_param = rcv_param;
- h->snd_param = snd_param;
}
+
+ h->os = a;
+ h->rcv = rcv;
+ h->snd = snd;
+ h->rcv_param = rcv_param;
+ h->snd_param = snd_param;
+ h->position = 0;
+ h->length = 0;
+ h->max = 0;
+ h->length_set = 0;
+ h->state = SM_INIT;
const int r = httpc_state_machine(h, url, op);
if (r != HTTPC_YIELD && r != HTTPC_REUSE)
a->state = NULL; /* make sure this is not reused */
Two ways to reproduce when using persistent connections:
HEAD
followed byGET
-> sinceHEAD
doesn't have callbacks (but has allocatedh
), no data callback will be used for theGET
request- Consecutive
GET
s -> length wasn't reset so httpc requested invalid data (IIRC) - Consecutive
GET
s without state reset -> standard headers weren't added
Note that this is assuming httpc_op_heap
is only going to be called once per request. I don't know if that's always the case (async + yield?).
from httpc.
Yeah, that isn't going to work when the HTTPC_YIELD
option is set.
from httpc.
Related Issues (12)
- Possible Bug on chunked request: missing crlf after chunk size HOT 1
- Content-Length set during PUT/POST method HOT 1
- Error with responses other than OK HOT 2
- User http headers HOT 2
- post with response HOT 1
- Disable retry mechanism HOT 2
- HTTP 1.0 range support? HOT 3
- Hello~ Could you please provide a sample code for how to send messages httpc POST method? HOT 1
- Add context pointer to httpc_options HOT 3
- Accessing Content-Length without manual parsing
- Separate HTTP status codes from function return values HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpc.