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 7, 2024
1 parent c3d9e18 commit 1fb9fd7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 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,18 @@ func (d *Dispatcher) Dispatch(data yggdrasil.Data) error {
}

if r.Value().(bool) {
URL, err := url.Parse(string(data.Content))
// Because the data.Content field is typed as json.RawMessage, it must first be
// unmarshalled into a Go string before parsing as a URL.
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 1fb9fd7

Please sign in to comment.