Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

"allSPDYHeaderFields" get path error #146

Open
szrexzhu opened this issue Jul 5, 2016 · 2 comments
Open

"allSPDYHeaderFields" get path error #146

szrexzhu opened this issue Jul 5, 2016 · 2 comments

Comments

@szrexzhu
Copy link

szrexzhu commented Jul 5, 2016

I try to use CocoaSPDY visit our SPDY Proxy Server in my QQ Browser,meet a bug:

Visit http://m.sohu.com/n/452167131/?wscrid=15084_2,get a 301 redirect,the reason is that we have a error path:'/n/452167131?wscrid=15084_2',lost '/' when we use 'url.path'.

- (NSDictionary *)allSPDYHeaderFields
{
    NSDictionary *httpHeaders = self.allHTTPHeaderFields;
    NSURL *url = self.URL;

    static NSSet *invalidKeys;
    static NSSet *reservedKeys;
    static dispatch_once_t initialized;
    dispatch_once(&initialized, ^{
        invalidKeys = [[NSSet alloc] initWithObjects:
            @"connection", @"keep-alive", @"proxy-connection", @"transfer-encoding", nil
        ];

        reservedKeys = [[NSSet alloc] initWithObjects:
            @"method", @"path", @"version", @"host", @"scheme", nil
        ];
    });

    //----by rex----begin
    //Error:
    //Visit http://m.sohu.com/n/452167131/?wscrid=15084_2,get a 301 redirect,
    //the reason is that we have a error path:'/n/452167131?wscrid=15084_2',lost '/'
    //when we use 'url.path'.
    //
    //Reason:
    //Apple doc for 'url.path': If the path has a trailing slash, it is stripped.
    //
    //Solution:
    //http://markmail.org/message/cigyetgyjcvwsyx5#query:+page:1+mid:g4pmkeourikefc3p+state:results
    //NSString* s = @"http://example.com/path/to/id%3D8528/" ;
    //    NSLog(@"       given: %@", s) ;
    //    NSURL* url = [NSURL URLWithString:s] ;
    //    NSString* cocoaPath = [url path] ;
    //    NSString* cfPath = (NSString*)CFBridgingRelease(CFURLCopyPath((CFURLRef)url));
    //    NSString* cfstrictPath = (NSString*)CFBridgingRelease(CFURLCopyStrictPath((CFURLRef)url, NULL)) ;
    //    NSLog(@"   cocoaPath: %@", cocoaPath) ;
    //    NSLog(@"      cfPath: %@", cfPath) ;
    //    NSLog(@"cfstrictPath: %@", cfstrictPath) ;
    //
    //Result:
    //given: http://example.com/path/to/id%3D8528/
    //cocoaPath: /path/to/id=8528
    //cfPath: /path/to/id%3D8528/
    //cfstrictPath: path/to/id%3D8528/
    //


//    NSString *escapedPath = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
//            kCFAllocatorDefault,
//            (__bridge CFStringRef)url.path,
//            NULL,
//            CFSTR("?"),
//            kCFStringEncodingUTF8));

//    NSMutableString *path = [[NSMutableString alloc] initWithString:escapedPath];

    NSMutableString *path = [[NSMutableString alloc] initWithString:(NSString*)CFBridgingRelease(CFURLCopyPath((CFURLRef)url))];
    //----end----


    NSString *query = url.query;
    if (query) {
        [path appendFormat:@"?%@", query];
    }

    NSString *fragment = url.fragment;
    if (fragment) {
        [path appendFormat:@"#%@", fragment];
    }
......
@kgoodier
Copy link
Contributor

kgoodier commented Jul 5, 2016

This looks like the code out of the 'master' branch. The 'develop' branch has changed this a bit, to use NSURLComponents for the url pieces. It seems to behave correctly for the path segment of your url. You may want to try running the 'develop' branch code for this issue, and possibly your others. In the meantime, I'll merge 'develop' into 'master' and create a new release but it may take a few weeks.

@szrexzhu
Copy link
Author

szrexzhu commented Jul 7, 2016

Thanks

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

No branches or pull requests

2 participants