Revision: 29265 http://sourceforge.net/p/bibdesk/svn/29265 Author: hofman Date: 2025-05-05 22:20:05 +0000 (Mon, 05 May 2025) Log Message: ----------- Use GET for small URLs and POST onlyfor vry larg URLs, not all SRU servers may accept long URLs or POST
Modified Paths: -------------- trunk/bibdesk/BDSKSRUGroupServer.m Modified: trunk/bibdesk/BDSKSRUGroupServer.m =================================================================== --- trunk/bibdesk/BDSKSRUGroupServer.m 2025-05-05 16:07:57 UTC (rev 29264) +++ trunk/bibdesk/BDSKSRUGroupServer.m 2025-05-05 22:20:05 UTC (rev 29265) @@ -125,9 +125,8 @@ return [components URL]; } -// because wwe use POST, we only need to escape &, as that can be confused with the separator static NSString *escapeQueryTerm(NSString *string) { - return [string stringByReplacingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"&"] withString:@"%26"]; + return [string stringByAddingPercentEscapesForQueryTerm]; } - (NSString *)searchQueryWithRange:(NSRange)range { @@ -156,11 +155,19 @@ authorization = nil; } + NSMutableURLRequest *request = nil; NSString *query = [self searchQueryWithRange:range]; - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self serverURL]]; - [request setHTTPMethod:@"POST"]; - [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-type"]; - [request setHTTPBody:[query dataUsingEncoding:NSUTF8StringEncoding]]; + NSURL *url = [self serverURL]; + NSString *urlString = [url absoluteString]; + if ([urlString length] + [query length] < 4096) { + url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", urlString, query]]; + request = [NSMutableURLRequest requestWithURL:url]; + } else { + request = [NSMutableURLRequest requestWithURL:url]; + [request setHTTPMethod:@"POST"]; + [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-type"]; + [request setHTTPBody:[query dataUsingEncoding:NSUTF8StringEncoding]]; + } if (authorization) [request setValue:authorization forHTTPHeaderField:@"Authorization"]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit