Git Product home page Git Product logo

Comments (4)

denravonska avatar denravonska commented on July 17, 2024 1

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.

howerj avatar howerj commented on July 17, 2024

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.

denravonska avatar denravonska commented on July 17, 2024

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 by GET -> since HEAD doesn't have callbacks (but has allocated h), no data callback will be used for the GETrequest
  • Consecutive GETs -> length wasn't reset so httpc requested invalid data (IIRC)
  • Consecutive GETs 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.

howerj avatar howerj commented on July 17, 2024

Yeah, that isn't going to work when the HTTPC_YIELD option is set.

from httpc.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.