From 7bc00c3da71be79553d72b842736aef7d4b00985 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Tue, 6 Apr 2021 08:28:11 +0800 Subject: [PATCH] client & server: revert changes to parse the response * There is no need to do so. * Our issue was caused by missing Content-Length --- src/client.rs | 9 --------- src/server.rs | 10 +++------- src/util.rs | 18 +----------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/client.rs b/src/client.rs index d3ceacf..de420ac 100644 --- a/src/client.rs +++ b/src/client.rs @@ -173,15 +173,6 @@ impl Client { record.data().data().to_vec(), ), ); - // Try to parse the record; if failed, fail this entire query - let parsed_record_data = crate::util::parse_record_data(record.data()); - - if let Err(_) = parsed_record_data { - return Err("Failed to parse response from upstream".to_string()); - } else if let Ok(None) = parsed_record_data { - return Err("Upstream did not respond our query".to_string()); - } - ret.push(owned_record); } Ok(ret) diff --git a/src/server.rs b/src/server.rs index e4ebf25..47687ea 100644 --- a/src/server.rs +++ b/src/server.rs @@ -226,13 +226,9 @@ impl Server { // Set up the answer section let mut answer_builder = question_builder.answer(); for r in records { - if let Ok(Some(data)) = crate::util::parse_record_data(r.data()) { - answer_builder - .push(Record::new(r.owner().clone(), r.class(), r.ttl(), data)) - .map_err(|_| "Max answer size exceeded".to_string())?; - } else { - return Err("Cannot parse record data responded by resolver client".to_string()); - } + answer_builder + .push(r) + .map_err(|_| "Max answer size exceeded".to_string())?; } Ok(answer_builder.into_message()) } diff --git a/src/util.rs b/src/util.rs index 3c78dfd..697d6fa 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,11 +1,4 @@ -use domain::{ - base::{ - octets::{ParseError, Parser}, - rdata::{ParseRecordData, UnknownRecordData}, - Message, ParsedDname, - }, - rdata::AllRecordData, -}; +use domain::base::Message; use js_sys::{Math, Promise}; use std::ops::Add; use std::{collections::hash_map::DefaultHasher, hash::Hasher}; @@ -28,15 +21,6 @@ pub fn parse_dns_wireformat(msg: &[u8]) -> Result>, String> { .map_err(|_| "Failed to parse DNS wireformat message".to_string()) } -pub fn parse_record_data>( - record: &UnknownRecordData, -) -> Result>>, ParseError> { - AllRecordData::parse_data( - record.rtype(), - &mut Parser::from_ref(record.data().as_ref()), - ) -} - // Rust wrapper around JS functions // For convenience, and also to work around bugs in rust-analyzer // which thinks all JS functions are "unsafe"