Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
6697e7f9
Commit
6697e7f9
authored
9 years ago
by
Jorge Canizales
Browse files
Options
Downloads
Patches
Plain Diff
Don’t append -bin automatically to binary request headers.
parent
bbba491b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/objective-c/GRPCClient/private/NSDictionary+GRPC.m
+15
-29
15 additions, 29 deletions
src/objective-c/GRPCClient/private/NSDictionary+GRPC.m
with
15 additions
and
29 deletions
src/objective-c/GRPCClient/private/NSDictionary+GRPC.m
+
15
−
29
View file @
6697e7f9
...
...
@@ -40,8 +40,8 @@
@interface
NSData
(
GRPCMetadata
)
+
(
instancetype
)
grpc_dataFromMetadataValue
:(
grpc_metadata
*
)
metadata
;
// Fill a metadata object with the binary value in this NSData
and the given key
.
-
(
void
)
grpc_initMetadata
:(
grpc_metadata
*
)
metadata
withKey
:(
NSString
*
)
key
;
// Fill a metadata object with the binary value in this NSData.
-
(
void
)
grpc_initMetadata
:(
grpc_metadata
*
)
metadata
;
@end
@implementation
NSData
(
GRPCMetadata
)
...
...
@@ -50,9 +50,7 @@
return
[
self
dataWithBytes
:
metadata
->
value
length
:
metadata
->
value_length
];
}
-
(
void
)
grpc_initMetadata
:(
grpc_metadata
*
)
metadata
withKey
:(
NSString
*
)
key
{
// TODO(jcanizales): Encode Unicode chars as ASCII.
metadata
->
key
=
[
key
stringByAppendingString
:
@"-bin"
].
UTF8String
;
-
(
void
)
grpc_initMetadata
:(
grpc_metadata
*
)
metadata
{
metadata
->
value
=
self
.
bytes
;
metadata
->
value_length
=
self
.
length
;
}
...
...
@@ -63,8 +61,8 @@
@interface
NSString
(
GRPCMetadata
)
+
(
instancetype
)
grpc_stringFromMetadataValue
:(
grpc_metadata
*
)
metadata
;
// Fill a metadata object with the textual value in this NSString
and the given key
.
-
(
void
)
grpc_initMetadata
:(
grpc_metadata
*
)
metadata
withKey
:(
NSString
*
)
key
;
// Fill a metadata object with the textual value in this NSString.
-
(
void
)
grpc_initMetadata
:(
grpc_metadata
*
)
metadata
;
@end
@implementation
NSString
(
GRPCMetadata
)
...
...
@@ -74,22 +72,8 @@
encoding:
NSASCIIStringEncoding
];
}
-
(
void
)
grpc_initMetadata
:(
grpc_metadata
*
)
metadata
withKey
:(
NSString
*
)
key
{
if
([
key
hasSuffix
:
@"-bin"
])
{
// Disallow this, as at best it will confuse the server. If the app really needs to send a
// textual header with a name ending in "-bin", it can be done by removing the suffix and
// encoding the NSString as a NSData object.
//
// Why raise an exception: In the most common case, the developer knows this won't happen in
// their code, so the exception isn't triggered. In the rare cases when the developer can't
// tell, it's easy enough to add a sanitizing filter before the header is set. There, the
// developer can choose whether to drop such a header, or trim its name. Doing either ourselves,
// silently, would be very unintuitive for the user.
[
NSException
raise
:
NSInvalidArgumentException
format:
@"Metadata keys ending in '-bin' are reserved for NSData values."
];
}
// TODO(jcanizales): Encode Unicode chars as ASCII.
metadata
->
key
=
key
.
UTF8String
;
// Precondition: This object contains only ASCII characters.
-
(
void
)
grpc_initMetadata
:(
grpc_metadata
*
)
metadata
{
metadata
->
value
=
self
.
UTF8String
;
metadata
->
value_length
=
self
.
length
;
}
...
...
@@ -124,19 +108,21 @@
return
metadata
;
}
// Preconditions: All keys are ASCII strings. Keys ending in -bin have NSData values; the others
// have NSString values.
-
(
grpc_metadata
*
)
grpc_metadataArray
{
grpc_metadata
*
metadata
=
gpr_malloc
([
self
count
]
*
sizeof
(
grpc_metadata
));
int
i
=
0
;
for
(
id
key
in
self
)
{
grpc_metadata
*
current
=
metadata
;
for
(
NSString
*
key
in
self
)
{
id
value
=
self
[
key
];
grpc_metadata
*
current
=
&
metadata
[
i
]
;
if
([
value
respondsToSelector
:
@selector
(
grpc_initMetadata
:
withKey
:
)])
{
[
value
grpc_initMetadata
:
current
withKey
:
key
];
current
->
key
=
key
.
UTF8String
;
if
([
value
respondsToSelector
:
@selector
(
grpc_initMetadata
:)])
{
[
value
grpc_initMetadata
:
current
];
}
else
{
[
NSException
raise
:
NSInvalidArgumentException
format:
@"Metadata values must be NSString or NSData."
];
}
i
+=
1
;
++
current
;
}
return
metadata
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment