0

I cannot find out what's wrong with abs_path being "/search?search=Thrust+washers", and, what's more, how to debug this.

Class: error

Exception: {badmatch,{error,invalid_uri}}

Req: {http_request,'GET',{abs_path,"/search?search=Thrust+washers"},{1,1}}

Stack: [{myurl,pass_through,1,
               [{file,"/usr/local/lib/yaws/voxx/ebin/myurl.erl"},{line,507}]},

Line 506:
    Http_result = httpc:request(Url),
    {ok, {{V, S, R}, _, _}} = Http_result,

It seems to be caused by + (or %20) characters in Url, but these are perfectly legal.

I found Yaws process died: {{badmatch,<<>>} and the answer of Steve Vinoski, but cannot make use of it due to lack of experience.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
kklepper
  • 763
  • 8
  • 13

1 Answers1

0

I don't know the exact nature of your application, but I'm guessing that what it's doing is that Yaws receives a request on a URL with a query containing the data you show, and then your code is attempting to use the Yaws-parsed URL to make a request as an HTTP client. I was able to duplicate your problem with this sort of setup.

I believe the '+' character in your query has to be URL-encoded because '+' is listed as reserved in the "Uniform Resource Identifier (URI): Generic Syntax" specification, Section 2.2 (RFC3986); it is normally used to represent space characters in queries.

Using the Erlang functions in the uri_string module to compose a query, we see that it gets encoded:

1> uri_string:compose_query([{"search", "Thrust+washers"}]).
"search=Thrust%2Bwashers"
2> uri_string:dissect_query("search=Thrust%2Bwashers").
[{"search","Thrust+washers"}]

We see the same in Python:

>>> import urllib.parse
>>> urllib.parse.urlencode({'search': 'Thrust+washers'})
'search=Thrust%2Bwashers'

If you make a curl request to Yaws using a URL with the query encoded in this manner, Yaws decodes your query as {"page","x+y"} as you'd expect.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
  • Thanks a lot! Right on Spot! Very instructive. And sorry for the misspelling of your name. – kklepper Dec 08 '22 at 00:33
  • uri_string:compose_query([{"search", "Thrust washers"}]). "search=Thrust+washers" So blank is transformed in +; urlencode does the trick – kklepper Dec 08 '22 at 00:40