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

Wildcard in PipelineStage.add(_, contentTypes:) doesn't work as expected #286

Open
jordanpwood opened this issue Mar 18, 2019 · 0 comments

Comments

@jordanpwood
Copy link

I am trying add a content transformer to the parsing phase of the Siesta pipeline using the following:

self.service.configure("**") { [weak self] in // all endpoints
        guard let strongSelf = self else {
            return
        }
        
        $0.pipeline[.parsing].add(TextResponseTransformer(), contentTypes: ["*​/xml"])

        /*  other configuration code */
}

However, when a network response with the content type application/xml; charset=utf-8 comes in, the content type is not matching to the regex that Siesta has generated in the add call. I have written the following playground code, which I believe replicates what Siesta is doing when it looks for a matching content type:

import UIKit

var str = "application/xml; charset=utf-8"

let regex = try! NSRegularExpression(pattern: "^[^/+]+\\/xml($|;)")
print(regex.description)
let fullRange = NSRange(location: 0, length: (str as NSString).length)

let match = regex.firstMatch(in: str, options: [], range: fullRange)

As far as I can tell, this should replicate what Siesta does in the file Regex+Siesta.swiftin its extension NSRegularExpression.matches(). However, the above playground code gets a match while Siesta does not. If I change the pipeline transformer add to:

$0.pipeline[.parsing].add(TextResponseTransformer(), contentTypes: ["application/xml"])

It works as expected. Why won't the pattern */xml work? It seems like it should.

Thanks for the help with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant