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

Move HTTP gateway types to interface #696

Merged
merged 2 commits into from
Jun 20, 2022
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
33 changes: 1 addition & 32 deletions src/internet_identity/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,11 @@ use ic_cdk::trap;
use ic_certified_map::HashTree;
use internet_identity::metrics_encoder::MetricsEncoder;
use internet_identity::signature_map::SignatureMap;
use internet_identity_interface::{HeaderField, HttpRequest, HttpResponse};
use serde::Serialize;
use serde_bytes::{ByteBuf, Bytes};
use std::borrow::Cow;

pub type HeaderField = (String, String);

#[derive(Clone, Debug, CandidType, Deserialize)]
struct Token {}

#[derive(Clone, Debug, CandidType, Deserialize)]
enum StreamingStrategy {
Callback { callback: Func, token: Token },
}

#[derive(Clone, Debug, CandidType, Deserialize)]
struct StreamingCallbackHttpResponse {
body: ByteBuf,
token: Option<Token>,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct HttpRequest {
method: String,
url: String,
headers: Vec<(String, String)>,
body: ByteBuf,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct HttpResponse {
status_code: u16,
headers: Vec<HeaderField>,
body: Cow<'static, Bytes>,
streaming_strategy: Option<StreamingStrategy>,
}

impl ContentType {
pub fn to_mime_type_string(&self) -> String {
match self {
Expand Down
1 change: 0 additions & 1 deletion src/internet_identity/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::assets::init_assets;
use crate::http::{HeaderField, HttpRequest, HttpResponse};
use crate::AddTentativeDeviceResponse::{AddedTentatively, AnotherDeviceTentativelyAdded};
use crate::RegistrationState::{DeviceRegistrationModeActive, DeviceTentativelyAdded};
use crate::VerifyTentativeDeviceResponse::{NoDeviceToVerify, WrongCode};
Expand Down
37 changes: 35 additions & 2 deletions src/internet_identity_interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use candid::{CandidType, Deserialize, Principal};
use serde_bytes::ByteBuf;
use candid::{CandidType, Deserialize, Func, Principal};
use serde_bytes::{ByteBuf, Bytes};
use std::borrow::Cow;

pub type UserNumber = u64;
pub type CredentialId = ByteBuf;
Expand Down Expand Up @@ -126,3 +127,35 @@ pub struct IdentityAnchorInfo {
pub devices: Vec<DeviceData>,
pub device_registration: Option<DeviceRegistrationInfo>,
}

pub type HeaderField = (String, String);

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct Token {}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub enum StreamingStrategy {
Callback { callback: Func, token: Token },
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct StreamingCallbackHttpResponse {
pub body: ByteBuf,
pub token: Option<Token>,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct HttpRequest {
pub method: String,
pub url: String,
pub headers: Vec<(String, String)>,
pub body: ByteBuf,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct HttpResponse {
pub status_code: u16,
pub headers: Vec<HeaderField>,
pub body: Cow<'static, Bytes>,
pub streaming_strategy: Option<StreamingStrategy>,
}