octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #56624] webwrite only supports form-encoded pa


From: Ivan
Subject: [Octave-bug-tracker] [bug #56624] webwrite only supports form-encoded parameters, not user-defined data
Date: Wed, 20 Apr 2022 06:15:43 -0400 (EDT)

Follow-up Comment #2, bug #56624 (project octave):

Usage of Key-Value pairs together with option 'Headerfields' or an option
'Headerfields' with array greater than 1x2 
causes error in Octave 6.2.0 webwrite and weboptions functions

webwrite:
1. key-value pairs processing

## If MediaType is set by the user, append it to other headers.
  if (! strcmp (options.CharacterEncoding, "auto"))
    options.HeaderFields{end+1, 1} = "Content-Type";
    options.HeaderFields{end, 2} = [options.MediaType, ...
                                    "; charset=", options.CharacterEncoding];
  endif

  if (! isempty (options.KeyName))
    options.HeaderFields{end+1, 1} = options.KeyName;
    options.HeaderFields{end, 2} = options.KeyValue;
  endif

        1. may be changed to match options class check for field size in 
weboptions

  ## If MediaType is set by the user, append it to other headers.
  if (! strcmp (options.CharacterEncoding, "auto"))
      options.HeaderFields(end+1, 1:2) = {"Content-Type",...
                                          [options.MediaType, ...
                                           "; charset=",
options.CharacterEncoding]}; 
  endif

  if (! isempty (options.KeyName))
      if iscell(options.KeyName)
          l = length(options.KeyName);
          if (size(options.KeyName,1) == 1)&&(l~=1)
              options.HeaderFields(end+1:end+l, 1:2) = [options.KeyName',
options.KeyValue'];
          else
              options.HeaderFields(end+1:end+l, 1:2) = [options.KeyName,
options.KeyValue];
          end
      else
          options.HeaderFields(end+1, 1:2) = {options.KeyName,
options.KeyValue};
      endif
  endif

1. headerfields reshape

## Flatten the cell array because the internal processing takes place on
  ## a flattened array.
  options.HeaderFields = options.HeaderFields(:)';

        1. may be changed to match cell array format in the backend function
'__restful_service__' (not Key ... Key, Value ... Value, but Key, Value, ...
Key, Value)

options.HeaderFields = reshape(options.HeaderFields',1,[]);

1. varargin option 

response = __restful_service__ (url, varargin, options);

or

response = __restful_service__ (url, varargin{:}, options);

1. iscellstr check blocks cell string argument <data>

elseif  (! iscellstr (varargin))
      error ("webwrite: DATA must be a string");

or

elseif  (! iscellstr (varargin{1}))

        1. '__restful_service__' requires in  argument <data> a cell string of 
size
1xN or Nx1 with key-value order


weboptions:
1. Headerfields check

    function f = set.HeaderFields (f, value)
      ...
        elseif (columns (value) != 2)
          error ("weboptions: HeaderFields must be of size m-by-2");
      ...

        1. may be changed to match 1xN reshaped array for '__restful_service__'

    function f = set.HeaderFields (f, value)
      ...
        elseif (columns (value) != 2) && mod(numel(value),2) ~= 0
          error ("weboptions_test: HeaderFields must be of size m-by-2");
      ...


(file #53117, file #53118, file #53119)

    _______________________________________________________

Additional Item Attachment:

File name: weboptions_test.m              Size:13 KB
    <https://file.savannah.gnu.org/file/weboptions_test.m?file_id=53117>

File name: test_octave_1.m                Size:0 KB
    <https://file.savannah.gnu.org/file/test_octave_1.m?file_id=53118>

File name: webwrite_test.m                Size:4 KB
    <https://file.savannah.gnu.org/file/webwrite_test.m?file_id=53119>



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?56624>

_______________________________________________
  Сообщение отправлено по Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]