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

Decorator: use AFHTTPRequestSerializer to encode request url #31

Merged
merged 3 commits into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Decorator: use RXRHTTPRequestSerializer to encode request url
  • Loading branch information
huangduyu committed Nov 24, 2016
commit 854ddb996ea902366e109088c077c40e2b0cd731
22 changes: 5 additions & 17 deletions Rexxar/Core/Extension/RXRURLRequestSerialization.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
// RXRURLRequestSerialization.h
// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// UIColor+Rexxar.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File name typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh...

// Rexxar
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// Created by bigyelow on 11/24/16.
// Copyright © 2016 Douban.Inc. All rights reserved.
// Note: This file is copied from AFURLRequestSerialization.h
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import <Foundation/Foundation.h>
#import <TargetConditionals.h>
Expand Down
22 changes: 5 additions & 17 deletions Rexxar/Core/Extension/RXRURLRequestSerialization.m
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
// RXRURLRequestSerialization.m
// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// UIColor+Rexxar.h
// Rexxar
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// Created by bigyelow on 11/24/16.
// Copyright © 2016 Douban.Inc. All rights reserved.
// Note: This file is copied from AFURLRequestSerialization.m
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "RXRURLRequestSerialization.h"

Expand Down
16 changes: 7 additions & 9 deletions Rexxar/Decorator/RXRRequestDecorator.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2016 Douban.Inc. All rights reserved.
//

#import "RXRURLRequestSerialization.h"
#import "RXRRequestDecorator.h"

#import "NSURL+Rexxar.h"
Expand Down Expand Up @@ -42,7 +43,7 @@ - (void)decorateRequest:(NSMutableURLRequest *)request
}];

// Request url parameters
NSMutableDictionary *parametersEncoded = [NSMutableDictionary dictionaryWithDictionary:self.parameters];
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:self.parameters];
for (NSString *pair in [request.URL.query componentsSeparatedByString:@"&"]) {

NSArray *keyValuePair = [pair componentsSeparatedByString:@"="];
Expand All @@ -51,17 +52,14 @@ - (void)decorateRequest:(NSMutableURLRequest *)request
}

NSString *key = [keyValuePair[0] stringByRemovingPercentEncoding];
if (parametersEncoded[key] == nil) {
parametersEncoded[key] = [keyValuePair[1] stringByRemovingPercentEncoding];
if (parameters[key] == nil) {
parameters[key] = [keyValuePair[1] stringByRemovingPercentEncoding];
}
}

NSString *query = [NSURL rxr_queryFromDictionary:parametersEncoded];
if (query) {
NSURLComponents *urlComps = [NSURLComponents componentsWithURL:request.URL resolvingAgainstBaseURL:YES];
urlComps.query = query;
request.URL = urlComps.URL;
}
request = [[[RXRHTTPRequestSerializer serializer] requestBySerializingRequest:request
withParameters:parameters
error:nil] mutableCopy];
}

@end