Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option to ignore "Content-Type" for config/source/url ? #52

Open
liispon opened this issue Aug 31, 2022 · 4 comments
Open

add an option to ignore "Content-Type" for config/source/url ? #52

liispon opened this issue Aug 31, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@liispon
Copy link

liispon commented Aug 31, 2022

some sites may not provide a correct "Content-Type" header.

@Davincible
Copy link
Contributor

Example?

@liispon
Copy link
Author

liispon commented Sep 2, 2022

I tried spring config server. It returned "Content-Type: text/plain" for a YAML file.
It made "config/source/url" can't work with it.
So I wonder if we could add an option to work around such cases.

@Davincible
Copy link
Contributor

I see, do you get an error? If so could you paste the full error

@liispon
Copy link
Author

liispon commented Sep 6, 2022

Example code:

        enc := yaml.NewEncoder()
	urlSource := url.NewSource(
		url.WithURL(path),
		source.WithEncoder(enc),
	)
	conf, err := config.NewConfig(
		config.WithReader(mjson.NewReader(reader.WithEncoder(enc))),
	)
       conf.Load(urlSource)

error message:

Error creating config: invalid character 'b' looking for beginning of value

And If remove code in url.go dealing with 'content-type', it could parse the YAML correctly.

func (u *urlSource) Read() (*source.ChangeSet, error) {
	rsp, err := http.Get(u.url)
	if err != nil {
		return nil, err
	}
	defer rsp.Body.Close()

	b, err := io.ReadAll(rsp.Body)
	if err != nil {
		return nil, err
	}

	// ft := format(rsp.Header.Get("Content-Type"))
	// if len(ft) == 0 {
	ft := u.opts.Encoder.String()
	//}

	cs := &source.ChangeSet{
		Data:      b,
		Format:    ft,
		Timestamp: time.Now(),
		Source:    u.String(),
	}
	cs.Checksum = cs.Sum()

	return cs, nil
}

@xpunch xpunch added the enhancement New feature or request label Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants