Skip to content

Commit

Permalink
fix: Fixed dispatching of URL for worker in remote content mode
Browse files Browse the repository at this point in the history
* When worker was in remote content mode, then yggdrasil still
  expects raw data as valid JSON document. URL like:
  http://example.com/ is not valid JSON document. It could be
  e.g. "http://example.com/"
* Not sure if this is the best solution, but it solves the issue
  described in issue #208
  • Loading branch information
jirihnidek committed Feb 20, 2024
1 parent c3d9e18 commit 3ce7c59
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/work/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,17 @@ func (d *Dispatcher) Dispatch(data yggdrasil.Data) error {
}

if r.Value().(bool) {
URL, err := url.Parse(string(data.Content))
// The type of data.Content is raw string, but it has to be valid JSON document.
// It means that it has to be something like '"http://example.com"' and
// not only 'http://example.com'
rawUrlStr := string(data.Content)
if rawUrlStr[0] != '"' && rawUrlStr[len(rawUrlStr)-1] != '"' {
return fmt.Errorf("data (containing URL) not encapsulated by quotation marks")
}
urlStr := rawUrlStr[1 : len(rawUrlStr)-1]
URL, err := url.Parse(urlStr)
if err != nil {
return fmt.Errorf("cannot parse content as URL: %v", err)
return fmt.Errorf("cannot parse content %v as URL: %v", urlStr, err)
}
if config.DefaultConfig.DataHost != "" {
URL.Host = config.DefaultConfig.DataHost
Expand Down

0 comments on commit 3ce7c59

Please sign in to comment.