Message ID | 20200924085230.13711-1-christian.storm@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | channel_curl: Strip newline from received key-unique headers | expand |
On 24.09.20 10:52, Christian Storm wrote: > Strip \n from received headers' values to ease further > processing. Alike, make the reply headers key-unique, > i.e., save only one of multiple same-key headers. > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > corelib/channel_curl.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c > index 48e6853..0f09682 100644 > --- a/corelib/channel_curl.c > +++ b/corelib/channel_curl.c > @@ -420,10 +420,13 @@ static size_t channel_callback_headers(char *buffer, size_t size, size_t nitems, > key = info; > val = p + 1; /* Next char after ':' */ > while(isspace((unsigned char)*val)) val++; > - dict_insert_value(dict, key, val); > - TRACE("%s : %s", key, val); > + /* Remove '\n' from header's value. */ > + *strchrnul(val, '\n') = '\0'; > + /* For multiple same-key headers, only the last is saved. */ > + dict_set_value(dict, key, val); This is a change in behavior, but there are currently no use case, so it is IMHO ok. > + TRACE("Header processed: %s : %s", key, val); > } else { > - TRACE("Header not processed: %s", info); > + TRACE("Header not processed: '%s'", info); > } > > free(info); > Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
Hi Stefano, > On 24.09.20 10:52, Christian Storm wrote: > > Strip \n from received headers' values to ease further > > processing. Alike, make the reply headers key-unique, > > i.e., save only one of multiple same-key headers. > > > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > > --- > > corelib/channel_curl.c | 9 ++++++--- > > 1 file changed, 6 insertions(+), 3 deletions(-) > > > > diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c > > index 48e6853..0f09682 100644 > > --- a/corelib/channel_curl.c > > +++ b/corelib/channel_curl.c > > @@ -420,10 +420,13 @@ static size_t channel_callback_headers(char *buffer, size_t size, size_t nitems, > > key = info; > > val = p + 1; /* Next char after ':' */ > > while(isspace((unsigned char)*val)) val++; > > - dict_insert_value(dict, key, val); > > - TRACE("%s : %s", key, val); > > + /* Remove '\n' from header's value. */ > > + *strchrnul(val, '\n') = '\0'; > > + /* For multiple same-key headers, only the last is saved. */ > > + dict_set_value(dict, key, val); > > This is a change in behavior, but there are currently no use case, so it > is IMHO ok. Yes, the only one (openly) using it is server_general.c and I couldn't imagine a use case where multiple same-key headers could make sense? They could as well be encoded in one header key as multiple (separated) values. Having multiple same-key headers only complicates things in terms of properly processing them in SWUpdate as you always have to consider this edge case then and have to choose the right data structures, i.e., a set is out of scope, a bag isn't.... > > + TRACE("Header processed: %s : %s", key, val); > > } else { > > - TRACE("Header not processed: %s", info); > > + TRACE("Header not processed: '%s'", info); > > } > > > > free(info); > > > > Acked-by: Stefano Babic <sbabic@denx.de> Kind regards, Christian
diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 48e6853..0f09682 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -420,10 +420,13 @@ static size_t channel_callback_headers(char *buffer, size_t size, size_t nitems, key = info; val = p + 1; /* Next char after ':' */ while(isspace((unsigned char)*val)) val++; - dict_insert_value(dict, key, val); - TRACE("%s : %s", key, val); + /* Remove '\n' from header's value. */ + *strchrnul(val, '\n') = '\0'; + /* For multiple same-key headers, only the last is saved. */ + dict_set_value(dict, key, val); + TRACE("Header processed: %s : %s", key, val); } else { - TRACE("Header not processed: %s", info); + TRACE("Header not processed: '%s'", info); } free(info);
Strip \n from received headers' values to ease further processing. Alike, make the reply headers key-unique, i.e., save only one of multiple same-key headers. Signed-off-by: Christian Storm <christian.storm@siemens.com> --- corelib/channel_curl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)