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/"
* Solves issue #208
  • Loading branch information
jirihnidek committed Mar 6, 2024
1 parent c3d9e18 commit 4b12a7e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/work/dispatcher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package work

import (
"encoding/json"
"fmt"
"io"
"net/url"
Expand Down Expand Up @@ -205,9 +206,19 @@ 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 JSON string fragment
// containing URL. It means that it has to be something like '"http://example.com"'
// and not only 'http://example.com'
var urlStr string
err = json.Unmarshal(data.Content, &urlStr)
if err != nil {
return fmt.Errorf("cannot parse content as URL: %v", err)
return fmt.Errorf("unable to unmarshal JSON string fragment: %v", err)
}

// When string fragment was unmarshalled, then we can try to parse string as URL
URL, err := url.Parse(urlStr)
if err != nil {
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 4b12a7e

Please sign in to comment.