Skip to content

Commit

Permalink
apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alce committed May 13, 2021
1 parent c92e57c commit bcfb942
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions tonic-web/tonic-web/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ impl<B> GrpcWebCall<B> {
}
}

// This is to avoid passing a slice of bytes with a length that the base64
// decoder would consider invalid.
#[inline]
fn max_decodable(&self) -> usize {
(self.buf.len() / 4) * 4
Expand Down
22 changes: 9 additions & 13 deletions tonic-web/tonic-web/src/cors.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
use std::sync::Arc;

pub(crate) use http::header::ACCESS_CONTROL_ALLOW_CREDENTIALS as ALLOW_CREDENTIALS;
pub(crate) use http::header::ACCESS_CONTROL_ALLOW_HEADERS as ALLOW_HEADERS;
pub(crate) use http::header::ACCESS_CONTROL_ALLOW_METHODS as ALLOW_METHODS;
pub(crate) use http::header::ACCESS_CONTROL_ALLOW_ORIGIN as ALLOW_ORIGIN;
pub(crate) use http::header::ACCESS_CONTROL_EXPOSE_HEADERS as EXPOSE_HEADERS;
pub(crate) use http::header::ACCESS_CONTROL_MAX_AGE as MAX_AGE;
pub(crate) use http::header::ACCESS_CONTROL_REQUEST_HEADERS as REQUEST_HEADERS;
pub(crate) use http::header::ACCESS_CONTROL_REQUEST_METHOD as REQUEST_METHOD;
pub(crate) use http::header::ORIGIN;
use http::{header, HeaderMap, HeaderValue, Method};
use tracing::debug;

use self::headers::*;
use crate::config::Config;

pub(crate) mod headers {
pub(crate) use http::header::ACCESS_CONTROL_ALLOW_CREDENTIALS as ALLOW_CREDENTIALS;
pub(crate) use http::header::ACCESS_CONTROL_ALLOW_HEADERS as ALLOW_HEADERS;
pub(crate) use http::header::ACCESS_CONTROL_ALLOW_METHODS as ALLOW_METHODS;
pub(crate) use http::header::ACCESS_CONTROL_ALLOW_ORIGIN as ALLOW_ORIGIN;
pub(crate) use http::header::ACCESS_CONTROL_EXPOSE_HEADERS as EXPOSE_HEADERS;
pub(crate) use http::header::ACCESS_CONTROL_MAX_AGE as MAX_AGE;
pub(crate) use http::header::ACCESS_CONTROL_REQUEST_HEADERS as REQUEST_HEADERS;
pub(crate) use http::header::ACCESS_CONTROL_REQUEST_METHOD as REQUEST_METHOD;
pub(crate) use http::header::ORIGIN;
}

const DEFAULT_ALLOWED_METHODS: &[Method; 2] = &[Method::POST, Method::OPTIONS];

#[derive(Debug, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions tonic-web/tonic-web/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use tracing::{debug, trace};

use crate::call::content_types::is_grpc_web;
use crate::call::{Encoding, GrpcWebCall};
use crate::cors::headers::{ORIGIN, REQUEST_HEADERS};
use crate::cors::Cors;
use crate::cors::{ORIGIN, REQUEST_HEADERS};
use crate::{BoxError, BoxFuture, Config};

const GRPC: &str = "application/grpc";
Expand Down Expand Up @@ -351,7 +351,7 @@ mod tests {

mod options {
use super::*;
use crate::cors::headers::{REQUEST_HEADERS, REQUEST_METHOD};
use crate::cors::{REQUEST_HEADERS, REQUEST_METHOD};
use http::HeaderValue;

const SUCCESS: StatusCode = StatusCode::NO_CONTENT;
Expand Down
5 changes: 5 additions & 0 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ impl Server {

/// Allow this server to accept http1 requests.
///
/// Accepting http1 requests is only useful when developing `grpc-web`
/// enabled services. If this setting is set to `true` but services are
/// not correctly configured to handle grpc-web requests, your server may
/// return confusing (but correct) protocol errors.
///
/// Default is `false`.
pub fn accept_http1(self, accept_http1: bool) -> Self {
Server {
Expand Down

0 comments on commit bcfb942

Please sign in to comment.